private void FillAddress( Account tempAccount , ITracingService tracingService , AccountKonturFocusModel accountFromKonturFocus , Account.AccountTypeEnum accountType = AccountTypeEnum.UL , Account.AddressTypeEnum addressType = AddressTypeEnum.Legal ) { tracingService.Trace("enter konturfocussynchronizationplugin.filladdress"); ParsedAddressRF addressObj = accountType == AccountTypeEnum.UL ? accountFromKonturFocus.UL?.legalAddress?.parsedAddressRF : accountFromKonturFocus.IP?.legalAddress?.parsedAddressRF; if (addressObj == null) { if (accountType == AccountTypeEnum.IP && accountFromKonturFocus != null) { ParsedAddressRF shortenedAddress = accountFromKonturFocus.IP?.shortenedAddress; if (shortenedAddress == null) { return; } addressObj = shortenedAddress; } else { return; } } tempAccount.Address1_AddressTypeCode = addressType; tempAccount.Address1_Line1 = GetAddressLine(addressObj, accountFromKonturFocus, accountType, addressType, tracingService); tracingService.Trace("exit konturfocussynchronizationplugin.filladdress"); }
private void CreateAccountAddress( IOrganizationService organizationService , ITracingService tracingService , Guid accountId , AccountKonturFocusModel accountData , AccountTypeEnum accountType , AddressTypeEnum addressType ) { tracingService.Trace("enter konturfocussynchronizationplugin.createaccountaddress"); ParsedAddressRF addressObj = null; if (accountData.UL != null) { addressObj = accountData.UL.legalAddress?.parsedAddressRF; } if (accountData.IP != null) { addressObj = accountData.IP.legalAddress?.parsedAddressRF; } if (addressObj == null) { if (accountType == AccountTypeEnum.IP && accountData != null) { ParsedAddressRF shortenedAddress = accountData.IP?.shortenedAddress; if (shortenedAddress == null) { return; } addressObj = shortenedAddress; } else { return; } } CustomerAddress customerAddress = new CustomerAddress { Line1 = GetAddressLine(addressObj, accountData, accountType, addressType, tracingService), ParentId = new EntityReference(Account.EntityLogicalName, accountId) }; customerAddress.Id = organizationService.Create(customerAddress); Account account = new Account { Id = accountId }; FillAddress(account, tracingService, accountData, accountType, addressType); organizationService.Update(account); tracingService.Trace("exit konturfocussynchronizationplugin.createaccountaddress"); }
private Account CreateFO( Account tempAccount , AccountKonturFocusModel accountFromKonturFocus , ITracingService tracingService ) { tempAccount.Name = accountFromKonturFocus.fullName; tempAccount.AccountType = AccountTypeEnum.UL; tempAccount.RegisteredOn = accountFromKonturFocus.accreditation?.startDate; tempAccount.Inn = accountFromKonturFocus.inn; tempAccount.Ogrn = accountFromKonturFocus.ogrn; tempAccount.Kpp = accountFromKonturFocus.kpp; ParsedAddressRF addressObj = accountFromKonturFocus.address; tempAccount.Address1_AddressTypeCode = AddressTypeEnum.Legal; tempAccount.Address1_Line1 = GetAddressLine(addressObj, accountFromKonturFocus, AccountTypeEnum.UL, AddressTypeEnum.Legal, tracingService); return(tempAccount); }
private string GetAddressLine( ParsedAddressRF addressObj , AccountKonturFocusModel accountFromKonturFocus , AccountTypeEnum accountType , AddressTypeEnum addressType , ITracingService tracingService ) { tracingService.Trace("enter konturfocussynchronizationplugin.getaddressline"); if (addressObj == null) { if (accountType == AccountTypeEnum.IP) { if (accountFromKonturFocus == null) { tracingService.Trace("accountfromkonturfocus is null"); return(""); } ParsedAddressRF shortenedAddress = accountFromKonturFocus.IP?.shortenedAddress; if (shortenedAddress == null) { tracingService.Trace("shortenedaddress is null"); return(""); } addressObj = shortenedAddress; } else { tracingService.Trace("accounttypeenum != ip"); return(""); } } string regionValue = addressObj?.regionName?.topoValue; string regionTopo = addressObj?.regionName?.topoFullName; string cityValue = addressObj?.city?.topoValue; string cityTopo = addressObj?.city?.topoFullName; string streetValue = addressObj?.street?.topoValue; string streetTopo = addressObj?.street?.topoFullName; string houseValue = addressObj?.house?.topoValue; string houseTopo = addressObj?.house?.topoFullName; string bulkValue = addressObj?.bulk?.topoValue; string bulkTopo = addressObj.bulk != null ? $", {addressObj?.bulk?.topoFullName} " : string.Empty; string flatValue = addressObj?.flat?.topoValue; string flatTopo = addressObj.flat != null ? $", {addressObj?.flat?.topoFullName} " : string.Empty; string zipCode = addressObj?.zipCode; if (!string.IsNullOrWhiteSpace(bulkTopo) && bulkTopo.Trim() == ",") { bulkTopo = " "; } string address1_StateOrProvince = @""; string address1_PostalCode = addressObj.zipCode; string address1_City = $"{cityTopo} {cityValue}"; if (!string.IsNullOrWhiteSpace(regionTopo) && regionTopo.ToUpper() == AddressMapper.CITY_TOPO) { address1_StateOrProvince = $"{regionTopo} {regionValue}"; } else { address1_StateOrProvince = $"{regionValue} {regionTopo}"; } if (!string.IsNullOrWhiteSpace(regionTopo) && regionTopo.ToUpper() == AddressMapper.REPUBLIC_TOPO) { address1_StateOrProvince = AddressMapper.Map(CountryPartTypeEnum.Republic, regionTopo, regionValue); } if (string.IsNullOrWhiteSpace(address1_City)) { if (addressObj.district != null) { string districtValue = addressObj?.district?.topoValue; string districtTopo = addressObj?.district?.topoFullName; address1_City = $"{districtValue} {districtTopo}"; } if (addressObj.settlement != null) { string settlement = addressObj?.settlement?.topoValue; if (string.IsNullOrWhiteSpace(streetValue)) { streetValue = settlement; } string settlementTopo = addressObj?.settlement?.topoFullName; if (string.IsNullOrWhiteSpace(streetTopo)) { streetTopo = settlementTopo; } } } else { if (addressObj.settlement != null) { string settlement = addressObj?.settlement?.topoValue; if (string.IsNullOrWhiteSpace(streetValue)) { streetValue = settlement; } string settlementTopo = addressObj?.settlement?.topoFullName; if (string.IsNullOrWhiteSpace(streetTopo)) { streetTopo = settlementTopo; } } } string address1_Line1 = $"{streetTopo} {streetValue}, {houseTopo} {houseValue}{bulkTopo}{bulkValue}{flatTopo}{flatValue}"; if (!string.IsNullOrWhiteSpace(streetTopo) && AddressMapper.StreetTopo.Contains(streetTopo.ToUpper())) { address1_Line1 = $"{streetValue} {streetTopo}, {houseTopo} {houseValue}{bulkTopo}{bulkValue}{flatTopo}{flatValue}"; } if (addressType == AddressTypeEnum.Legal) { if (!string.IsNullOrWhiteSpace(address1_PostalCode)) { address1_PostalCode += ", "; } if (!string.IsNullOrWhiteSpace(address1_StateOrProvince)) { address1_StateOrProvince += ", "; } if (!string.IsNullOrWhiteSpace(address1_City)) { address1_City += ", "; } } string addressLine = (address1_PostalCode + address1_StateOrProvince + address1_City + address1_Line1).ToUpper().Trim(); if (!string.IsNullOrWhiteSpace(addressLine) && addressLine.Substring(addressLine.Length - 1, 1) == ",") { addressLine = addressLine.Substring(0, addressLine.Length - 1); } tracingService.Trace("created line {0}", addressLine); tracingService.Trace("exit konturfocussynchronizationplugin.getaddressline"); return(addressLine); }