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