Api/Netina.Repository/Handlers/Warehouses/DeleteShippingCommandHandle...

25 lines
972 B
C#

using Microsoft.EntityFrameworkCore;
using Netina.Domain.Entities.Warehouses;
namespace Netina.Repository.Handlers.Warehouses;
public class DeleteShippingCommandHandler : IRequestHandler<DeleteShippingCommand, bool>
{
private readonly IRepositoryWrapper _repositoryWrapper;
public DeleteShippingCommandHandler(IRepositoryWrapper repositoryWrapper)
{
_repositoryWrapper = repositoryWrapper;
}
public async Task<bool> Handle(DeleteShippingCommand request, CancellationToken cancellationToken)
{
var ent = await _repositoryWrapper.SetRepository<Shipping>().TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (ent == null)
throw new AppException("Shipping not found", ApiResultStatusCode.NotFound);
_repositoryWrapper.SetRepository<Shipping>().Delete(ent);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}