using Brizco.Repository.Abstracts; namespace Brizco.Repository.Handlers.Position; public class UpdatePositionUserCommandHandler : IRequestHandler { private readonly IRepositoryWrapper _repositoryWrapper; public UpdatePositionUserCommandHandler(IRepositoryWrapper repositoryWrapper) { _repositoryWrapper = repositoryWrapper; } public async Task Handle(UpdatePositionUserCommand request, CancellationToken cancellationToken) { try { await _repositoryWrapper.BeginTransaction(cancellationToken); var entity = await _repositoryWrapper.SetRepository().TableNoTracking .FirstOrDefaultAsync(p => p.ApplicationUserId == request.UserId , cancellationToken); if (entity == null) throw new AppException("PositionUser not found"); var newEntity = PositionUser.Create(request.PositionId, request.UserId, request.ShiftPlanId); newEntity.Id = entity.Id; _repositoryWrapper.SetRepository().Update(newEntity); await _repositoryWrapper.SaveChangesAsync(cancellationToken); await _repositoryWrapper.CommitAsync(cancellationToken); return true; } catch (Exception) { await _repositoryWrapper.RollBackAsync(cancellationToken); throw; } } }