Api/Brizco.Repository/Handlers/ShiftPlans/DeleteShiftPlanCommandHandl...

20 lines
771 B
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.ShiftPlans;
2024-08-09 21:42:04 +03:30
public class DeleteShiftPlanCommandHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<DeleteShiftPlanCommand, bool>
{
public async Task<bool> Handle(DeleteShiftPlanCommand request, CancellationToken cancellationToken)
{
2024-08-09 21:42:04 +03:30
var shiftPlan = await repositoryWrapper.SetRepository<ShiftPlan>()
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id,cancellationToken);
if (shiftPlan == null)
throw new AppException("ShiftPlan not found", ApiResultStatusCode.NotFound);
2024-08-09 21:42:04 +03:30
repositoryWrapper.SetRepository<ShiftPlan>()
.Delete(shiftPlan);
2024-08-09 21:42:04 +03:30
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}