diff --git a/EnvelopeGenerator.Application/Common/Commands/UpdateCommand.cs b/EnvelopeGenerator.Application/Common/Commands/UpdateCommand.cs new file mode 100644 index 00000000..f93b7b85 --- /dev/null +++ b/EnvelopeGenerator.Application/Common/Commands/UpdateCommand.cs @@ -0,0 +1,59 @@ +using DigitalData.Core.Abstraction.Application.Repository; +using MediatR; +using System.Linq.Expressions; + +namespace EnvelopeGenerator.Application.Common.Commands; + +/// +/// +/// +/// +/// +public abstract record UpdateCommand : IRequest where TUpdateDto : class where TEntity : class +{ + /// + /// + /// + public TUpdateDto Update { get; init; } = null!; + + /// + /// + /// + /// + public abstract Expression> BuildQueryExpression(); +} + +/// +/// +/// +/// +/// +/// +public class UpdateCommandHandler : IRequestHandler + where TUpdateDto : class + where TEntity : class + where TCommand : UpdateCommand +{ + /// + /// + /// + protected readonly IRepository Repository; + + /// + /// + /// + /// + public UpdateCommandHandler(IRepository repository) + { + Repository = repository; + } + + /// + /// + /// + /// + /// + /// + public Task Handle(TCommand request, CancellationToken cancel) + => Repository.UpdateAsync(request.Update, request.BuildQueryExpression(), cancel); +} \ No newline at end of file