public async Task <int> ExecuteAsync(ContractDetailDto contractDetailDto) { var contractRepository = Uow.GetRepository <Contract>(); var contract = await contractRepository .AsQueryable() .Include(r => r.ProtectionDocType) .Include(r => r.Type) .Include(r => r.Category) .Include(r => r.RequestsForProtectionDoc).ThenInclude(cr => cr.Request).ThenInclude(cr => cr.ProtectionDocType) .FirstOrDefaultAsync(r => r.Id == contractDetailDto.Id); if (contract == null) { throw new DataNotFoundException(nameof(Contract), DataNotFoundException.OperationType.Update, contractDetailDto.Id); } _mapper.Map(contractDetailDto, contract); _numberGenerator.GenerateGosNumber(contract); contractRepository.Update(contract); Uow.SaveChanges(); return(contract.Id); }
public async Task <IActionResult> RegisterContract(int id, [FromBody] ContractDetailDto contractDetailDto) { contractDetailDto.Id = id; var updatedContractId = await Executor.GetCommand <RegisterContractCommand>().Process(c => c.ExecuteAsync(contractDetailDto)); var updatedContract = await Executor.GetQuery <GetContractByIdQuery>().Process(q => q.ExecuteAsync(updatedContractId)); var updatedContractDetailDto = Mapper.Map <Contract, ContractDetailDto>(updatedContract); return(Ok(updatedContractDetailDto)); }
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)); }
public async Task <IActionResult> Put(int id, [FromBody] ContractDetailDto detailDto) { var contract = await _mediator.Send(new Update.Command(id, detailDto)); return(Ok(contract)); }
public async Task <IActionResult> RegisterContract(int id, [FromBody] ContractDetailDto detailDto) { var contract = await _mediator.Send(new Register.Command(id, detailDto, User.Identity.GetUserId())); return(Ok(contract)); }
public async Task <IActionResult> Post([FromBody] ContractDetailDto detailDto) { var contract = await _mediator.Send(new Create.Command(detailDto, User.Identity.GetUserId())); return(Ok(contract)); }
public async Task <int> ExecuteAsync(ContractDetailDto contractDetailDto) { var contract = _mapper.Map <ContractDetailDto, Contract>(contractDetailDto); return(await ExecuteAsync(contract)); }