Api/Brizco.Repository/Handlers/Position/DeletePositionCommandHandle...

24 lines
974 B
C#

namespace Brizco.Repository.Handlers.Position;
public class DeletePositionCommandHandler : IRequestHandler<DeletePositionCommand, bool>
{
private readonly IRepositoryWrapper _repositoryWrapper;
public DeletePositionCommandHandler(IRepositoryWrapper repositoryWrapper)
{
_repositoryWrapper = repositoryWrapper;
}
public async Task<bool> Handle(DeletePositionCommand request, CancellationToken cancellationToken)
{
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>()
.TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null)
throw new AppException("Postion not found", ApiResultStatusCode.NotFound);
_repositoryWrapper.SetRepository<Domain.Entities.Complexes.Position>()
.Delete(shift);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}