public async Task <int> HandleAsync(UserDetailsDto userDetailDto) { var userByXin = Executor.GetQuery <GetUserByXinQuery>().Process(q => q.Execute(userDetailDto.Xin?.Trim())); if (userByXin != null) { throw new ValidationException("user with same xin already registered"); } var userByEmail = Executor.GetQuery <GetUserByEmailQuery>().Process(q => q.Execute(userDetailDto.Email?.Trim())); if (userByEmail != null) { throw new ValidationException("user with same email already registered"); } var newUser = _mapper.Map <UserDetailsDto, ApplicationUser>(userDetailDto); Executor.CommandChain() .AddCommand <CreateUserCommand>(c => c.Execute(newUser)) .AddCommand <UpdateUserRolesCommand>(c => c.Execute(newUser.Id, userDetailDto.RoleIds)) .AddCommand <UpdateUserIcgsCommand>(c => c.Execute(newUser.Id, userDetailDto.IcgsIds)) .ExecuteAllWithTransaction(); return(newUser.Id); }
public Result <bool> UpdateUser([FromBody] UserDto userDto) { try { if (CanUpdateUserValidation(userDto, out var failResult)) { return(failResult); } var roleName = ""; if (userDto.Role != null) { var roleNameResult = Executor.GetQuery <GetRoleByIdQuery>().Process(q => q.Execute(userDto.Role.Id)); if (roleNameResult.IsFailure) { return(Result <bool> .Fail(false, "Выбранная роль не найдена")); } roleName = roleNameResult.Value.Name; } Executor.CommandChain() .AddCommand <UpdateUserCommand>(c => c.Execute(userDto)) .AddCommand <UpdateUserClaimCommand>(c => c.Execute(UserClaimDto.UserNameClaim(userDto))) .AddCommand <UpdateUserClaimCommand>(c => c.Execute(UserClaimDto.UserRoleClaim(roleName, userDto.Id))) .AddCommand <UpdateUserClaimCommand>(c => c.Execute(UserClaimDto.UserGenderClaim(userDto))) .ExecuteAllWithTransaction(); return(Result <bool> .Ok(true)); } catch (Exception exception) { return(Result <bool> .Fail(false, $"{exception.Message}, {exception.StackTrace}")); } }
public async Task <IActionResult> Put(int id, [FromBody] RoleDetailsDto model) { var roleId = id; var roleDetailsDto = model; var role = await Executor.GetQuery <GetRoleByIdQuery>().Process(q => q.ExecuteAsync(roleId)); Mapper.Map(roleDetailsDto, role); try { Executor.CommandChain() .AddCommand <UpdateRoleCommand>(c => c.Execute(role)) .AddCommand <UpdateRoleClaimsCommand>(c => c.Execute(role, roleDetailsDto.Permissions)) .ExecuteAllWithTransaction(); Executor.GetHandler <UpdateRoleRouteStagesHandler>() .Process <int>(h => h.Execute(roleId, roleDetailsDto.RoleStages)); } catch (Exception e) { throw new DatabaseException(e.InnerException?.Message ?? e.Message); } return(NoContent()); }
//Вернул обнуление департамента и позиции public void Handle(UserDetailsDto userDetailsDto) { var userId = userDetailsDto.Id; var user = Executor.GetQuery <GetUserByIdQuery>().Process(q => q.Execute(userId)); if (user == null) { throw new DataNotFoundException(nameof(ApplicationUser), DataNotFoundException.OperationType.Read, userId); } _mapper.Map(userDetailsDto, user); user.CustomerId = null; user.Department = null; user.Position = null; try { Executor.CommandChain() .AddCommand <UpdateUserCommand>(c => c.Execute(user)) .AddCommand <UpdateUserRolesCommand>(c => c.Execute(userId, userDetailsDto.RoleIds)) .AddCommand <UpdateUserIcgsCommand>(c => c.Execute(userId, userDetailsDto.IcgsIds)) .AddCommand <UpdateUserIpcsCommand>(c => c.Execute(userId, userDetailsDto.IpcIds)) .ExecuteAllWithTransaction(); } catch (Exception e) { throw new DatabaseException(e.InnerException?.Message ?? e.Message); } }
public void Execute(Owner.Type ownerType, PaymentUse paymentUse, bool force) { Executor.CommandChain() .AddCommand <CreditPaymentInvoiceCommand>(c => c.Execute(ownerType, paymentUse, force)) .AddCommand <CreatePaymentUseCommand>(c => c.Execute(paymentUse)) .ExecuteAllWithTransaction(); Executor.GetCommand <UpdatePaymentStatusCommand>() .Process(c => c.Execute(paymentUse.PaymentId.Value)); }
public async Task <IActionResult> CreateSimilarSearchResults(int id, [FromBody] ExpertSearchSimilarDto[] expertSearchSimilarDtos) { Executor.CommandChain() //.AddCommand<ClearExpertSearchSimilarsCommand>(c => c.Execute(id)) .AddCommand <CreateExpertSearchSimilarsCommand>(c => c.Execute(expertSearchSimilarDtos)) .ExecuteAllWithTransaction(); var expertSearchSimilars = await Executor.GetQuery <GetExpertSearchSimilarsByRequestIdQuery>() .Process(q => q.Execute(id)); var expertSearchDtos = await GetMappedExpertSearchDtos(expertSearchSimilars); return(Ok(expertSearchDtos)); }
public async Task <IActionResult> Post([FromBody] ContractDetailDto contractDetailDto) { var contractId = await Executor.GetCommand <CreateContractCommand>().Process(c => c.ExecuteAsync(contractDetailDto)); var contract = await Executor.GetQuery <GetContractByIdQuery>().Process(q => q.ExecuteAsync(contractId)); var addressee = contract.Addressee; if (addressee != null /*&& string.IsNullOrWhiteSpace(contractDetailDto.Apartment) == false*/) { addressee.Apartment = contractDetailDto.Apartment; addressee.Address = contractDetailDto.AddresseeAddress; var сorrespondenceСustomerRoleId = _dictionaryHelper.GetDictionaryIdByCode(nameof(DicCustomerRole), _сorrespondenceCustomerRole); var сorrespondenceCustomer = new ContractCustomer() { CustomerId = contract.AddresseeId, ContractId = contractId, CustomerRoleId = сorrespondenceСustomerRoleId, Address = addressee.Address, AddressEn = addressee.AddressEn, AddressKz = addressee.AddressKz, DateCreate = DateTimeOffset.Now, DateUpdate = DateTimeOffset.Now }; await Executor.GetCommand <CreateContractCustomerCommand>().Process(q => q.ExecuteAsync(сorrespondenceCustomer)); await Executor.GetCommand <UpdateDicCustomerCommand>().Process(c => c.ExecuteAsync(addressee)); } var userId = NiisAmbientContext.Current.User.Identity.UserId; var contractWorkflow = await Executor.GetQuery <GetInitialContractWorkflowQuery>().Process(q => q.ExecuteAsync(contract, userId)); if (contractWorkflow != null) { await Executor.GetHandler <ProcessContractWorkflowHandler>().Process(h => h.Handle(contractWorkflow, userId)); } var contractRequestRelationsDtos = new List <ContractRequestRelationDto>(); var contractProtectionDocRelationDtos = new List <ContractProtectionDocRelationDto>(); foreach (var ownerDto in contractDetailDto.Owners) { contractRequestRelationsDtos.Add(new ContractRequestRelationDto { ContractId = contractId, Request = new RequestItemDto { Id = ownerDto.OwnerId } }); } foreach (var ownerDto in contractDetailDto.ProtectionDocsOwners) { contractProtectionDocRelationDtos.Add(new ContractProtectionDocRelationDto { ContractId = contractId, ProtectionDoc = new ProtectionDocItemDto { Id = ownerDto.OwnerId } }); } // var contractRequestRelationsDtos = contractDetailDto.RequestRelations.ToList(); Executor.CommandChain() .AddCommand <DeleteContractRequestRelationsCommand>(c => c.Execute(contractId, contractRequestRelationsDtos)) .AddCommand <CreateContractRequestRelationsCommand>(c => c.Execute(contractId, contractRequestRelationsDtos)) .AddCommand <UpdateContractRequestRelationsCommand>(c => c.Execute(contractId, contractRequestRelationsDtos)) .AddCommand <DeleteContractProtectionDocRelationsCommand>(c => c.Execute(contractId, contractProtectionDocRelationDtos)) .AddCommand <CreateContractProtectionDocRelationsCommand>(c => c.Execute(contractId, contractProtectionDocRelationDtos)) .AddCommand <UpdateContractProtectionDocRelationsCommand>(c => c.Execute(contractId, contractProtectionDocRelationDtos)) .ExecuteAllWithTransaction(); var createdContract = await Executor.GetQuery <GetContractByIdQuery>().Process(q => q.ExecuteAsync(contractId)); var createdContractDetailDto = Mapper.Map <Contract, ContractDetailDto>(createdContract); return(Ok(createdContractDetailDto)); }
public async Task <IActionResult> Put(int id, [FromBody] ContractDetailDto contractDetailDto) { var contractId = contractDetailDto.Id = id; var contractRequestRelationsDtos = new List <ContractRequestRelationDto>(); var contractProtectionDocRelationDtos = new List <ContractProtectionDocRelationDto>(); foreach (var ownerDto in contractDetailDto.Owners) { contractRequestRelationsDtos.Add(new ContractRequestRelationDto { ContractId = contractId, Request = new RequestItemDto { Id = ownerDto.OwnerId } }); } foreach (var ownerDto in contractDetailDto.ProtectionDocsOwners) { contractProtectionDocRelationDtos.Add(new ContractProtectionDocRelationDto { ContractId = contractId, ProtectionDoc = new ProtectionDocItemDto { Id = ownerDto.OwnerId } }); } var contract = Executor.GetQuery <GetContractByIdWithoutIncludingQuery>().Process(q => q.Execute(contractDetailDto.Id)); Mapper.Map(contractDetailDto, contract); Executor.CommandChain() .AddCommand <UpdateContractCommand>(c => c.Execute(contract)) .AddCommand <DeleteContractRequestRelationsCommand>(c => c.Execute(contractId, contractRequestRelationsDtos)) .AddCommand <CreateContractRequestRelationsCommand>(c => c.Execute(contractId, contractRequestRelationsDtos)) .AddCommand <UpdateContractRequestRelationsCommand>(c => c.Execute(contractId, contractRequestRelationsDtos)) .AddCommand <DeleteContractProtectionDocRelationsCommand>(c => c.Execute(contractId, contractProtectionDocRelationDtos)) .AddCommand <CreateContractProtectionDocRelationsCommand>(c => c.Execute(contractId, contractProtectionDocRelationDtos)) .AddCommand <UpdateContractProtectionDocRelationsCommand>(c => c.Execute(contractId, contractProtectionDocRelationDtos)) .ExecuteAllWithTransaction(); var updatedContract = await Executor.GetQuery <GetContractByIdQuery>().Process(q => q.ExecuteAsync(contractId)); var addressee = updatedContract.Addressee; if (addressee != null) { addressee.Apartment = contractDetailDto.Apartment; addressee.Address = contractDetailDto.AddresseeAddress; await Executor.GetCommand <UpdateDicCustomerCommand>().Process(c => c.ExecuteAsync(addressee)); } var updatedContractDetailDto = Mapper.Map <Contract, ContractDetailDto>(updatedContract); var contractWorkFlowRequest = new ContractWorkFlowRequest { ContractId = updatedContract.Id, NextStageUserId = updatedContract.CurrentWorkflow.CurrentUserId ?? default(int), NextStageCode = updatedContract.CurrentWorkflow.CurrentStage.Code, }; NiisWorkflowAmbientContext.Current.ContractWorkflowService.Process(contractWorkFlowRequest); return(Ok(updatedContractDetailDto)); }