2024-07-08 17:45:17 +03:30
|
|
|
|
namespace Brizco.Repository.Handlers.ShiftPlans;
|
2023-09-18 15:41:41 +03:30
|
|
|
|
|
2024-08-09 21:42:04 +03:30
|
|
|
|
public class DeleteShiftPlanCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
|
|
|
|
: IRequestHandler<DeleteShiftPlanCommand, bool>
|
2023-09-18 15:41:41 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<bool> Handle(DeleteShiftPlanCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-08-09 21:42:04 +03:30
|
|
|
|
var shiftPlan = await repositoryWrapper.SetRepository<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-08-09 21:42:04 +03:30
|
|
|
|
repositoryWrapper.SetRepository<ShiftPlan>()
|
2023-09-18 15:41:41 +03:30
|
|
|
|
.Delete(shiftPlan);
|
2024-08-09 21:42:04 +03:30
|
|
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
2023-09-18 15:41:41 +03:30
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|