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

19 lines
748 B
C#

namespace Brizco.Repository.Handlers.Shifts;
public class DeletePositionCommandHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<DeleteShiftCommand, bool>
{
public async Task<bool> Handle(DeleteShiftCommand request, CancellationToken cancellationToken)
{
var shift = await repositoryWrapper.SetRepository<Shift>()
.TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null)
throw new AppException("Routine not found", ApiResultStatusCode.NotFound);
repositoryWrapper.SetRepository<Shift>()
.Delete(shift);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}