Api/Brizco.Repository/Handlers/Positions/DeletePositionCommandHandle...

19 lines
763 B
C#
Raw Normal View History

namespace Brizco.Repository.Handlers.Positions;
2023-11-14 16:21:49 +03:30
2024-08-09 21:42:04 +03:30
public class DeletePositionCommandHandler(IRepositoryWrapper repositoryWrapper)
: IRequestHandler<DeletePositionCommand, bool>
2023-11-14 16:21:49 +03:30
{
public async Task<bool> Handle(DeletePositionCommand request, CancellationToken cancellationToken)
{
2024-08-09 21:42:04 +03:30
var shift = await repositoryWrapper.SetRepository<Position>()
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-08-09 21:42:04 +03:30
repositoryWrapper.SetRepository<Position>()
2023-11-14 16:21:49 +03:30
.Delete(shift);
2024-08-09 21:42:04 +03:30
await repositoryWrapper.SaveChangesAsync(cancellationToken);
2023-11-14 16:21:49 +03:30
return true;
}
}