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

19 lines
748 B
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.Shifts;
2024-08-09 21:42:04 +03:30
public class DeletePositionCommandHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<DeleteShiftCommand, bool>
{
public async Task<bool> Handle(DeleteShiftCommand request, CancellationToken cancellationToken)
{
2024-08-09 21:42:04 +03:30
var shift = await repositoryWrapper.SetRepository<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-08-09 21:42:04 +03:30
repositoryWrapper.SetRepository<Shift>()
.Delete(shift);
2024-08-09 21:42:04 +03:30
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}