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);
}