Api/Brizco.Repository/Handlers/ShiftPlan/DeleteShiftPlanCommandHandl...

26 lines
958 B
C#

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