- Updated `EnvelopeReceiverExecutor` to inherit from `SQLExecutor` and added `_erRepository` for enhanced data access. - Introduced `AddEnvelopeReceiverAsync` method for retrieving envelope receivers. - Modified `ReadById` in `EnvelopeReceiverRepository` to support flexible querying with new parameters. - Updated `ReadByIdAsync` to align with changes in `ReadById`.
42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
using Dapper;
|
|
using DigitalData.UserManager.Application.Contracts.Repositories;
|
|
using EnvelopeGenerator.Application.Contracts.SQLExecutor;
|
|
using EnvelopeGenerator.Application.SQL;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace EnvelopeGenerator.Infrastructure.Executor;
|
|
|
|
public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
|
{
|
|
private readonly IUserRepository _userRepository;
|
|
|
|
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, IUserRepository userRepository) : base(provider, sqlExecutorParamsOptions)
|
|
{
|
|
_userRepository = userRepository;
|
|
}
|
|
|
|
public async Task<Envelope?> CreateEnvelopeAsync(DynamicParameters parameters, bool addUser = true, CancellationToken cancellation = default)
|
|
{
|
|
using var connection = new SqlConnection(Params.ConnectionString);
|
|
var sql = Provider.GetRequiredService<EnvelopeCreateReadSQL>();
|
|
await connection.OpenAsync(cancellation);
|
|
var envelopes = await connection.QueryAsync<Envelope>(sql.Raw, parameters);
|
|
var envelope = envelopes.FirstOrDefault();
|
|
|
|
if (envelope is null)
|
|
return null;
|
|
|
|
// Add User
|
|
if (addUser)
|
|
{
|
|
var user = await _userRepository.ReadByIdAsync(envelope.UserId);
|
|
envelope.User = user;
|
|
}
|
|
|
|
return envelope;
|
|
}
|
|
} |