Api/Netina.Repository/Handlers/Discounts/DeleteDiscountCommandHandle...

17 lines
731 B
C#
Raw Permalink Normal View History

2024-08-09 21:55:16 +03:30
namespace Netina.Repository.Handlers.Discounts;
2024-02-12 22:01:15 +03:30
2024-08-09 21:55:16 +03:30
public class DeleteDiscountCommandHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<DeleteDiscountCommand, bool>
{
public async Task<bool> Handle(DeleteDiscountCommand request, CancellationToken cancellationToken)
{
2024-08-09 21:55:16 +03:30
var ent = await repositoryWrapper.SetRepository<Discount>().TableNoTracking
.FirstOrDefaultAsync(d => d.Id == request.Id, cancellationToken);
if (ent == null)
throw new AppException("Discount NotFound", ApiResultStatusCode.NotFound);
2024-08-09 21:55:16 +03:30
repositoryWrapper.SetRepository<Discount>().Delete(ent);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}