24 lines
965 B
C#
24 lines
965 B
C#
namespace Brizco.Repository.Handlers.Routine;
|
|
|
|
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)
|
|
{
|
|
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;
|
|
}
|
|
} |