24 lines
970 B
C#
24 lines
970 B
C#
namespace Brizco.Repository.Handlers.Position;
|
|
|
|
public class DeletePositionCommandHandler : IRequestHandler<DeletePositionCommand, bool>
|
|
{
|
|
private readonly IRepositoryWrapper _repositoryWrapper;
|
|
|
|
public DeletePositionCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
{
|
|
_repositoryWrapper = repositoryWrapper;
|
|
}
|
|
public async Task<bool> Handle(DeletePositionCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Complex.Position>()
|
|
.TableNoTracking
|
|
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
|
if (shift == null)
|
|
throw new AppException("Postion not found", ApiResultStatusCode.NotFound);
|
|
_repositoryWrapper.SetRepository<Domain.Entities.Complex.Position>()
|
|
.Delete(shift);
|
|
|
|
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
|
return true;
|
|
}
|
|
} |