public AddressDocument GetTransformedDocument(PostalAddressPayload payload, List <SyncFeedEntryLink> links) { AddressDocument address = new AddressDocument(); postalAddresstype postaladdress = payload.PostalAddresstype; if (String.IsNullOrEmpty(payload.LocalID)) { address.CrmId = payload.SyncUuid.ToString();// address.Id = GetLocalId(payload.SyncUuid); } else { address.Id = payload.LocalID; } address.address1.Value = postaladdress.address1; address.address2.Value = postaladdress.address2; address.address3.Value = postaladdress.address3; address.address4.Value = postaladdress.address4; address.country.Value = postaladdress.country; address.City.Value = postaladdress.townCity; address.postcode.Value = postaladdress.zipPostCode; if (!String.IsNullOrEmpty(address.Id)) { address.primaryaddress.Value = "true"; } else { address.primaryaddress.Value = postaladdress.primacyIndicator.ToString(); } if (!address.primaryaddress.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)) { if (postaladdress.type == postalAddressTypeenum.Correspondance) { address.primaryaddress.Value = "true"; } } return(address); }
private SalesInvoicePayload GetPayload(DataSets.Order.CalculatedOrdersRow row, DataSets.Order.CalculatedOrderDetailsDataTable detailDataTable, //DataSets.Order.DeletedOrderDetailsDataTable deletedOrderDetailsDataTable, NorthwindConfig config) { #region Declarations SalesInvoicePayload payload; string id; CountryCodes countryCodes = new CountryCodes(); #endregion id = row.OrderID.ToString(); payload = new SalesInvoicePayload(); payload.LocalID = id; payload.SyncUuid = GetUuid(id, "", SupportedResourceKinds.salesOrders); payload.SalesInvoicetype.active = true; payload.SalesInvoicetype.applicationID = id; payload.SalesInvoicetype.currency = config.CurrencyCode; payload.ForeignIds.Add("pricelist", Sage.Integration.Northwind.Application.API.Constants.DefaultValues.PriceList.ID); if (!row.IsCustomerIDNull()) { payload.ForeignIds.Add("tradingAccount", Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix + row.CustomerID); } if (!row.IsOrderDateNull()) { payload.SalesInvoicetype.date = row.OrderDate; payload.SalesInvoicetype.dateSpecified = true; } payload.SalesInvoicetype.lineCountSpecified = true; payload.SalesInvoicetype.lineCount = detailDataTable.Rows.Count; payload.SalesInvoicetype.discountTotalSpecified = true; payload.SalesInvoicetype.discountTotal = row.IsDiscountAmountNull() ? new decimal(0) : Convert.ToDecimal(row.DiscountAmount); payload.SalesInvoicetype.netTotalSpecified = true; payload.SalesInvoicetype.netTotal = row.IsTotalNetPriceNull() ? new decimal(0) : Convert.ToDecimal(row.TotalNetPrice); payload.SalesInvoicetype.carrierTotalPriceSpecified = true; payload.SalesInvoicetype.carrierTotalPrice = row.IsFreightNull() ? new decimal(0) : row.Freight; payload.SalesInvoicetype.grossTotalSpecified = true; payload.SalesInvoicetype.grossTotal = payload.SalesInvoicetype.netTotal; if (!row.IsRequiredDateNull()) { payload.SalesInvoicetype.deliveryDateSpecified = true; payload.SalesInvoicetype.deliveryDate = row.RequiredDate; } if (!row.IsShipViaNull()) { payload.SalesInvoicetype.deliveryMethod = row.ShipVia.ToString();; } postalAddresstype address = new postalAddresstype(); address.active = true; address.activeSpecified = true; address.address1 = row.IsShipAddressNull() ? "" : row.ShipAddress; address.applicationID = id; address.country = row.IsShipCountryNull() ? "" : row.ShipCountry; address.townCity = row.IsShipCityNull() ? "" : row.ShipCity; address.zipPostCode = row.IsShipPostalCodeNull() ? "" : row.ShipPostalCode; address.type = postalAddressTypeenum.Shipping; payload.SalesInvoicetype.postalAddresses = new postalAddresstype[1]; payload.SalesInvoicetype.postalAddresses[0] = address; payload.SalesInvoicetype.salesInvoiceLines = new salesInvoiceLinetype[detailDataTable.Rows.Count]; int index = 0; foreach (DataSets.Order.CalculatedOrderDetailsRow detailRow in detailDataTable.Rows) { SalesInvoiceLinePayload soPayload = GetLineItem(detailRow, config); payload.ForeignIds.Add( String.Format("salesInvoiceLines[{0}]", index.ToString()), soPayload.LocalID); foreach (string key in soPayload.ForeignIds.Keys)// (int foreignIdIndex = 0; foreignIdIndex <= soPayload.ForeignIds.Count; foreignIdIndex++) { string value; if (soPayload.ForeignIds.TryGetValue(key, out value)) { payload.ForeignIds.Add( String.Format("salesInvoiceLines[{0}]/{1}", index.ToString(), key), value); } } payload.SalesInvoicetype.salesInvoiceLines[index] = soPayload.SalesInvoiceLinetype; index++; } //foreach (DataSets.Order.DeletedOrderDetailsRow deletedRow in deletedOrderDetailsDataTable.Rows) //{ // lineItemDoc = new LineItemDocument(); // lineItemDoc.Id = deletedRow[0].ToString(); // lineItemDoc.LogState = LogState.Deleted; // doc.orderitems.Add(lineItemDoc); //} return(payload); }