- Enhanced `AddAutoMapper` configuration for flexibility. - Replaced `IEnvelopeMailService` with `IEnvelopeNotificationService`. - Migrated from `IUserRepository` to `EGDbContext` for data access. - Updated RabbitMQ configuration to use `AddMessagingServiceHttpClient`. - Removed `AddUserManager` and `AddDispatcher` registrations. - Added conditional `FluentValidation` dependencies for target frameworks. - Upgraded `MediatR` to 14.2.0 and `AutoMapper` to 16.2.0. - Added `HtmlSanitizer` dependency. - Improved error handling and logging in `ReadOnlyController`.
42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
#if NET
|
|
using Dapper;
|
|
using EnvelopeGenerator.Application.Common.Interfaces.SQLExecutor;
|
|
using EnvelopeGenerator.Application.Common.SQL;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace EnvelopeGenerator.Infrastructure.Executor;
|
|
|
|
public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
|
{
|
|
private readonly EGDbContext _dbContext;
|
|
|
|
public EnvelopeExecutor(IServiceProvider provider, IOptions<SQLExecutorParams> sqlExecutorParamsOptions, EGDbContext dbContext) : base(provider, sqlExecutorParamsOptions)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
[Obsolete("Use IRepository")]
|
|
public async Task<Envelope> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default)
|
|
{
|
|
using var connection = new SqlConnection(Params.ConnectionString);
|
|
var sql = Provider.GetRequiredService<EnvelopeCreateReadSQL>();
|
|
var formattedSql = string.Format(sql.Raw, userId.ToSqlParam(), title.ToSqlParam(), tfaEnabled.ToSqlParam(), message.ToSqlParam());
|
|
await connection.OpenAsync(cancellation);
|
|
var envelopes = await connection.QueryAsync<Envelope>(formattedSql);
|
|
var envelope = envelopes.FirstOrDefault()
|
|
?? throw new InvalidOperationException($"Envelope creation failed. Parameters:" +
|
|
$"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}.");
|
|
|
|
envelope.User = await _dbContext.Users
|
|
.AsNoTracking()
|
|
.FirstOrDefaultAsync(x => x.Id == envelope.UserId, cancellation);
|
|
|
|
return envelope;
|
|
}
|
|
}
|
|
#endif
|