20 lines
771 B
C#
20 lines
771 B
C#
namespace Brizco.Repository.Handlers.ShiftPlans;
|
|
|
|
public class DeleteShiftPlanCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
: IRequestHandler<DeleteShiftPlanCommand, bool>
|
|
{
|
|
public async Task<bool> Handle(DeleteShiftPlanCommand request, CancellationToken cancellationToken)
|
|
{
|
|
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);
|
|
|
|
repositoryWrapper.SetRepository<ShiftPlan>()
|
|
.Delete(shiftPlan);
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
|
|
return true;
|
|
}
|
|
} |