2023-09-18 15:41:41 +03:30
|
|
|
|
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)
|
|
|
|
|
|
{
|
2024-07-06 21:20:10 +03:30
|
|
|
|
var shiftPlan = await _repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
2023-11-05 18:00:05 +03:30
|
|
|
|
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id,cancellationToken);
|
2023-09-18 15:41:41 +03:30
|
|
|
|
|
|
|
|
|
|
if (shiftPlan == null)
|
|
|
|
|
|
throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound);
|
|
|
|
|
|
|
2024-07-06 21:20:10 +03:30
|
|
|
|
_repositoryWrapper.SetRepository<Domain.Entities.Shifts.ShiftPlan>()
|
2023-09-18 15:41:41 +03:30
|
|
|
|
.Delete(shiftPlan);
|
|
|
|
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|