Api/Brizco.Repository/Handlers/Shift/DeleteShiftCommandHandler.cs

24 lines
953 B
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.Shift;
2023-11-14 16:21:49 +03:30
public class DeletePositionCommandHandler : IRequestHandler<DeleteShiftCommand, bool>
{
private readonly IRepositoryWrapper _repositoryWrapper;
2023-11-14 16:21:49 +03:30
public DeletePositionCommandHandler(IRepositoryWrapper repositoryWrapper)
{
_repositoryWrapper = repositoryWrapper;
}
public async Task<bool> Handle(DeleteShiftCommand request, CancellationToken cancellationToken)
{
2024-07-06 21:20:10 +03:30
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>()
.TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null)
2023-11-14 16:21:49 +03:30
throw new AppException("Routine not found", ApiResultStatusCode.NotFound);
2024-07-06 21:20:10 +03:30
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.Shift>()
.Delete(shift);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}