Api/NetinaShop.Repository/Handlers/Accounting/UpdatePaymentCommandHandler.cs

31 lines
1.2 KiB
C#

using NetinaShop.Domain.Entities.Accounting;
namespace NetinaShop.Repository.Handlers.Accounting;
public class UpdatePaymentCommandHandler : IRequestHandler<UpdatePaymentCommand,bool>
{
private readonly IRepositoryWrapper _repositoryWrapper;
public UpdatePaymentCommandHandler(IRepositoryWrapper repositoryWrapper)
{
_repositoryWrapper = repositoryWrapper;
}
public async Task<bool> Handle(UpdatePaymentCommand request, CancellationToken cancellationToken)
{
var ent = await _repositoryWrapper.SetRepository<Payment>()
.TableNoTracking
.FirstOrDefaultAsync(p => p.Id == request.Id, cancellationToken);
if (ent == null)
throw new AppException("Payment not found", ApiResultStatusCode.NotFound);
var newEnt = Payment.Create(request.FactorNumber, request.Amount, request.Description, request.TransactionCode,
request.CardPan, request.Authority, request.Type, request.Status, request.OrderId, request.UserId);
newEnt.Id = ent.Id;
_repositoryWrapper.SetRepository<Payment>()
.Update(newEnt);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}