2024-08-09 21:55:16 +03:30
|
|
|
|
using Netina.Domain.Entities.Orders;
|
2023-12-31 19:55:22 +03:30
|
|
|
|
|
2024-04-16 20:01:34 +03:30
|
|
|
|
namespace Netina.Repository.Handlers.Orders;
|
2023-12-31 19:55:22 +03:30
|
|
|
|
|
2024-08-09 21:55:16 +03:30
|
|
|
|
public class DeleteOrderCommandHandler(IRepositoryWrapper repositoryWrapper) : IRequestHandler<DeleteOrderCommand, bool>
|
2023-12-31 19:55:22 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<bool> Handle(DeleteOrderCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-08-09 21:55:16 +03:30
|
|
|
|
var order = await repositoryWrapper.SetRepository<Order>()
|
2023-12-31 19:55:22 +03:30
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.FirstOrDefaultAsync(o => o.Id == request.OrderId, cancellationToken);
|
|
|
|
|
|
if (order == null)
|
|
|
|
|
|
throw new AppException("Order not found", ApiResultStatusCode.NotFound);
|
2024-08-09 21:55:16 +03:30
|
|
|
|
repositoryWrapper.SetRepository<Order>().Delete(order);
|
|
|
|
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
2023-12-31 19:55:22 +03:30
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|