public MiddlewareSyncRequest <BusinessPartnerSync> Create(BusinessPartnerIncomingResponse businessPartner) { var syncRequest = new MiddlewareSyncRequest <BusinessPartnerSync>(0, MiddlewareObjectTypes.Account.ToString()); var bpSync = BusinessPartnerSync(businessPartner); syncRequest.Data = bpSync; return(syncRequest); }
private BusinessPartnerSync BusinessPartnerSync(BusinessPartnerIncomingResponse businessPartner) { var sync = new BusinessPartnerSync(businessPartner.AccountDetails.ExternalID); sync.AccountDetails = businessPartner.AccountDetails; sync.Contacts = businessPartner.Contacts; sync.Locations = businessPartner.Locations; return(sync); }
private BusinessPartnerIncomingResponse ParseSapQueryResponseForIncoming(BusinessPartnerResponseMessage_sync sapResponse) { BusinessPartnerIncomingResponse response = SetLocationAndContactIdsForIncoming(sapResponse); if (sapResponse.BusinessPartner != null) { var bp = sapResponse.BusinessPartner[0]; response.AccountDetails = new AccountDetailsIncoming(); response.AccountDetails.ExternalID = bp.InternalID; response.AccountDetails.Status = bp.LifeCycleStatusCode.GetEnumDescription(); response.AccountDetails.Name = bp.Organisation != null ? bp.Organisation.FirstLineName : null; var defaultLocation = response.Locations.Where(x => x.isDefault == true).FirstOrDefault(); if (defaultLocation != null) { response.AccountDetails.Website = defaultLocation.Website; response.AccountDetails.Email = defaultLocation.Email; } response.AccountDetails.VendorNum = bp.ApprovedVendor1; response.AccountDetails.ApprovedVendor = bp.ApprovedVendor; response.AccountDetails.CompanyType = bp.CompanyType; response.AccountDetails.AccountTypes = new List <string>(); if (sapResponse.BusinessPartner[0].CustomerIndicator) { var custResponse = _customerService.GetCustomerDetails(bp.InternalID); response.AccountDetails.CustomerDetails = custResponse.CustomerDetails != null ? custResponse.CustomerDetails : new AccountTypeDetails(); response.AccountDetails.AccountTypes.Add("customer"); //hierarchy var hierarchy = _hierarchyService.IsAccountAssignedToHierarchy(bp.InternalID); if (hierarchy.ParentId != null) { response.AccountDetails.Hierarchy = hierarchy; } } if (sapResponse.BusinessPartner[0].SupplierIndicator) { var suppResponse = _supplierService.GetSupplierDetails(bp.InternalID); response.AccountDetails.SupplierDetails = suppResponse.SupplierDetails != null ? suppResponse.SupplierDetails : new AccountTypeDetails(); response.AccountDetails.AccountTypes.Add("supplier"); } } BaseResponse tempRes = SapLogParser.ParseSapResponseLog(sapResponse.Log); response.Errors = tempRes.Errors; response.Warnings = tempRes.Warnings; return(response); }
private BusinessPartnerIncomingResponse SetLocationAndContactIdsForIncoming(BusinessPartnerResponseMessage_sync queryResponse) { var response = new BusinessPartnerIncomingResponse(); response.Locations = new List <LocationDetails>(); response.Contacts = new List <ContactDetails>(); if (queryResponse.BusinessPartner[0] != null) { if (queryResponse.BusinessPartner[0].AddressInformation != null) { foreach (var addressInformation in queryResponse.BusinessPartner[0].AddressInformation) { var location = new LocationDetails(); if (addressInformation.Address != null && addressInformation.Address.PostalAddress != null) { var postalAddress = addressInformation.Address.PostalAddress; location.Address1 = postalAddress.CareOfName; location.Address2 = postalAddress.AdditionalStreetPrefixName; location.Address4 = postalAddress.StreetSuffixName; location.HouseNo = postalAddress.HouseID; location.Street = postalAddress.StreetName; location.City = postalAddress.CityName; location.StateExternalId = postalAddress.RegionCode != null ? postalAddress.RegionCode.Value : null; location.District = postalAddress.DistrictName; location.CountryExternalId = postalAddress.CountryCode; location.Website = addressInformation.Address.WebURI; location.Email = addressInformation.Address.EmailURI != null ? addressInformation.Address.EmailURI.Value : null; location.PostalCode = postalAddress.StreetPostalCode; } if (addressInformation.AddressUsage != null) { location.LocationTypeExternalId = new List <string>(); if (queryResponse.BusinessPartner[0].AddressInformation.Count() == 1) { location.isDefault = true; location.LocationTypeExternalId.Add("BILL_TO"); location.LocationTypeExternalId.Add("SHIP_TO"); } else { foreach (var addressUsage in addressInformation.AddressUsage) { if (addressUsage.AddressUsageCode.Value == "BILL_TO") { if (addressUsage.DefaultIndicator == true) { location.LocationTypeExternalId.Add("BILL_TO"); } } else { if (addressUsage.AddressUsageCode.Value == "XXDEFAULT") { location.isDefault = true; } if (addressUsage.AddressUsageCode.Value == "SHIP_TO") { location.LocationTypeExternalId.Add(addressUsage.AddressUsageCode.Value); } } } } } location.ExternalId = addressInformation.UUID != null ? addressInformation.UUID.Value : null; response.Locations.Add(location); } } if (queryResponse.BusinessPartner[0].ContactPerson != null) { foreach (var sapContact in queryResponse.BusinessPartner[0].ContactPerson) { var contact = new ContactDetails(); contact.FirstName = sapContact.GivenName; contact.LastName = sapContact.FamilyName; contact.OfficePhone = sapContact.WorkplaceTelephone[0] != null ? sapContact.WorkplaceTelephone[0].FormattedNumberDescription : null; contact.Email = sapContact.WorkplaceEmailURI != null ? sapContact.WorkplaceEmailURI.Value : null; contact.LocationExternalId = sapContact.WorkplaceBusinessAddressUUID != null ? sapContact.WorkplaceBusinessAddressUUID.Value : null; contact.ExternalId = sapContact.BusinessPartnerContactInternalID; response.Contacts.Add(contact); } } } return(response); }