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>
|
2023-12-20 10:37:44 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<bool> Handle(DeleteDiscountCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-08-09 21:55:16 +03:30
|
|
|
|
var ent = await repositoryWrapper.SetRepository<Discount>().TableNoTracking
|
2023-12-20 10:37:44 +03:30
|
|
|
|
.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);
|
2023-12-20 10:37:44 +03:30
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|