Api/Brizco.Repository/Handlers/Routines/DeleteRoutineCommandHandler.cs

19 lines
807 B
C#

namespace Brizco.Repository.Handlers.Routines;
public class DeleteRoutineCommandHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<DeleteRoutineCommand, bool>
{
public async Task<bool> Handle(DeleteRoutineCommand request, CancellationToken cancellationToken)
{
var shift = await repositoryWrapper.SetRepository<Domain.Entities.Routines.Routine>()
.TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null)
throw new AppException("Postion not found", ApiResultStatusCode.NotFound);
repositoryWrapper.SetRepository<Domain.Entities.Routines.Routine>()
.Delete(shift);
await repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}