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

24 lines
966 B
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.Routines;
2023-11-14 16:21:49 +03:30
public class DeleteRoutineCommandHandler : IRequestHandler<DeleteRoutineCommand, bool>
{
private readonly IRepositoryWrapper _repositoryWrapper;
public DeleteRoutineCommandHandler(IRepositoryWrapper repositoryWrapper)
{
_repositoryWrapper = repositoryWrapper;
}
public async Task<bool> Handle(DeleteRoutineCommand request, CancellationToken cancellationToken)
{
2024-07-06 21:20:10 +03:30
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Routines.Routine>()
2023-11-14 16:21:49 +03:30
.TableNoTracking
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
if (shift == null)
throw new AppException("Postion not found", ApiResultStatusCode.NotFound);
2024-07-06 21:20:10 +03:30
_repositoryWrapper.SetRepository<Domain.Entities.Routines.Routine>()
2023-11-14 16:21:49 +03:30
.Delete(shift);
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
return true;
}
}