private async Task <CommitAgentResponse> CommitAgent(CommitAgentRequestData commitAgentRequestData, string signature) { return(await _client.CommitAgentAsync(new CommitAgentRequest { ContractVersion = _navApiContractVer, MessageContractVersion = _navMsgContractVer, Signature = signature, EnableExceptionStackTrace = false, CommitAgentReqData = commitAgentRequestData })); }
public async Task <dto.CommitAgencyResponse> AddAgency(dto.CommitAgencyRequest commitAgencyRequest) { if (!string.IsNullOrEmpty(await _sessionBag.AgentName())) { throw new dto.ResponseErrorException(dto.Enumerations.ResponseErrorCode.AlreadyLoggedIn, string.Format("Unable to create agency, Logged in as {0}", await _sessionBag.AgentName())); } var signature = !string.IsNullOrEmpty(await _sessionBag.Signature()) ? await _sessionBag.Signature() : await _userSessionService.GetAnonymousSharedSignature(); // check if organization already exists GetOrganizationResponse getResponse = null; try { getResponse = await _agentClient.GetOrganizationAsync(new GetOrganizationRequest { ContractVersion = _navApiContractVer, MessageContractVersion = _navMsgContractVer, Signature = signature, EnableExceptionStackTrace = false, GetOrganizationReqData = new GetOrganizationRequestData { OrganizationCode = commitAgencyRequest.Organization.OrganizationCode.ToUpper() } }); } catch { } if (getResponse != null && getResponse.Organization != null) { throw new dto.ResponseErrorException(dto.Enumerations.ResponseErrorCode.AgencyAlreadyExists, string.Format("Agency {0} already exists: {1}.", getResponse.Organization.OrganizationCode, getResponse.Organization.OrganizationName)); } // check if agent already exists (by login name) dto.FindAgentsResponse findAgentResponse = null; try { findAgentResponse = await _agentService.FindAgent(new dto.FindAgentRequestData { AgentName = new dto.SearchString { SearchType = dto.Enumerations.SearchType.ExactMatch, Value = commitAgencyRequest.CommitAgentRequestData.Agent.LoginName.ToLower() }, DomainCode = _newskiesSettings.AgentDomain }); } catch { } if (findAgentResponse != null && findAgentResponse.FindAgentResponseData != null && findAgentResponse.FindAgentResponseData.FindAgentList != null && findAgentResponse.FindAgentResponseData.FindAgentList.Length != 0) { throw new dto.ResponseErrorException(dto.Enumerations.ResponseErrorCode.AgentAlreadyExists, string.Format("Agent login name'{0}' already exists. ", commitAgencyRequest.CommitAgentRequestData.Agent.LoginName.ToLower())); } // create organization var commitOrganizationResp = await _agentClient.CommitOrganizationAsync(new CommitOrganizationRequest { ContractVersion = _navApiContractVer, MessageContractVersion = _navMsgContractVer, Signature = signature, EnableExceptionStackTrace = false, Organization = Mapper.Map <Organization>(commitAgencyRequest.Organization) }); // create master agent var mappedAgentRequest = Mapper.Map <CommitAgentRequestData>(commitAgencyRequest.CommitAgentRequestData); mappedAgentRequest.Agent.AgentIdentifier.OrganizationCode = commitOrganizationResp.Organization.OrganizationCode; mappedAgentRequest.Agent.AuthenticationType = AuthenticationType.Password; var commitAgentResponse = await _agentClient.CommitAgentAsync(new CommitAgentRequest { ContractVersion = _navApiContractVer, MessageContractVersion = _navMsgContractVer, Signature = signature, EnableExceptionStackTrace = false, CommitAgentReqData = mappedAgentRequest }); return(new dto.CommitAgencyResponse { Organization = Mapper.Map <dto.Organization>(commitOrganizationResp.Organization), CommitAgentResponseData = Mapper.Map <dto.CommitAgentResponseData>(commitAgentResponse.CommitAgentResData) }); }