예제 #1
0
        public AccountDocument GetTransformedDocument(TradingAccountPayload payload, List <SyncFeedEntryLink> links)
        {
            AccountDocument    document       = new AccountDocument();
            tradingAccounttype tradingAccount = payload.TradingAccount;

            document.addresses = new AddressDocumentCollection();
            if (tradingAccount.postalAddresses != null && tradingAccount.postalAddresses != null)
            {
                foreach (postalAddresstype postalAddress in tradingAccount.postalAddresses)
                {
                    PostalAddressPayload postalAdressPayload = new PostalAddressPayload();
                    postalAdressPayload.PostalAddresstype = postalAddress;
                    postalAdressPayload.SyncUuid          = StringToGuid(postalAddress.uuid);
                    AddressDocument address = _postalAdressTransformation.GetTransformedDocument(postalAdressPayload, Helper.ReducePayloadPath(links));
                    document.addresses.Add(address);
                }
            }
            bool hasMainAdress = false;

            for (int index = 0; index < document.addresses.documents.Count; index++)
            {
                AddressDocument address = document.addresses.documents[index] as AddressDocument;
                if ((address.primaryaddress.Value != null) && (address.primaryaddress.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainAdress = true;
                }
            }
            if ((!hasMainAdress) && (document.addresses.documents.Count > 0))
            {
                AddressDocument address = document.addresses.documents[0] as AddressDocument;
                address.primaryaddress.Value = "true";
            }
            if (String.IsNullOrEmpty(payload.LocalID))
            {
                document.CrmId = payload.SyncUuid.ToString();//
                document.Id    = GetLocalId(payload.SyncUuid);
            }
            else
            {
                document.Id = payload.LocalID;
            }
            document.currencyid.Value = tradingAccount.currency;
            document.emails           = new EmailsDocumentCollection();
            if (tradingAccount.emails != null && tradingAccount.emails != null)
            {
                foreach (emailtype email in tradingAccount.emails)
                {
                    EmailPayload emailPayload = new EmailPayload();
                    emailPayload.Emailtype = email;
                    emailPayload.SyncUuid  = StringToGuid(email.uuid);
                    EmailDocument emailDocument = _emailAdressTransformation.GetTransformedDocument(emailPayload, Helper.ReducePayloadPath(links));
                    document.emails.Add(emailDocument);
                }
            }
            document.name.Value = tradingAccount.name;
            // ????? document.onhold
            document.people = new PeopleDocumentCollection();
            if (tradingAccount.contacts != null && tradingAccount.contacts != null)
            {
                foreach (contacttype contact in tradingAccount.contacts)
                {
                    ContactPayload contactPayload = new ContactPayload();
                    contactPayload.Contacttype = contact;
                    contactPayload.SyncUuid    = StringToGuid(contact.uuid);
                    PersonDocument person = _contactTransformation.GetTransformedDocument(contactPayload, Helper.ReducePayloadPath(links));
                    document.people.Add(person);
                }
            }
            bool hasMainPerson = false;

            for (int index = 0; index < document.people.documents.Count; index++)
            {
                PersonDocument person = document.people.documents[index] as PersonDocument;
                if ((person.primaryperson.Value != null) && (person.primaryperson.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainPerson = true;
                }
            }
            if ((!hasMainPerson) && (document.people.documents.Count > 0))
            {
                PersonDocument person = document.people.documents[0] as PersonDocument;
                person.primaryperson.Value = "true";
            }

            document.phones = new PhonesDocumentCollection();
            if (tradingAccount.phones != null && tradingAccount.phones != null)
            {
                foreach (phoneNumbertype phoneNumber in tradingAccount.phones)
                {
                    PhoneNumberPayload phoneNumberPayload = new PhoneNumberPayload();
                    phoneNumberPayload.PhoneNumbertype = phoneNumber;
                    //phoneNumberPayload.SyncUuid = GetUuid(phoneNumber.applicationID);
                    PhoneDocument phone = _phoneNumberTransformation.GetTransformedDocument(phoneNumberPayload, Helper.ReducePayloadPath(links));
                    document.phones.Add(phone);
                }
            }
            document.customerSupplierFlag.Value = tradingAccount.customerSupplierFlag;
            return(document);
        }
        public AccountDocument GetTransformedDocument(TradingAccountFeedEntry feedEntry)
        {
            AccountDocument accountDocument = new AccountDocument();

            #region Postal adresses
            accountDocument.addresses = new AddressDocumentCollection();

            if (feedEntry.postalAddresses != null && feedEntry.postalAddresses != null)
            {
                foreach (PostalAddressFeedEntry postalAdressEntry in feedEntry.postalAddresses.Entries)
                {
                    AddressDocument address = _postalAdressTransformation.GetTransformedDocument(postalAdressEntry);
                    accountDocument.addresses.Add(address);
                }
            }

            bool hasMainAdress = false;
            for (int index = 0; index < accountDocument.addresses.documents.Count; index++)
            {
                AddressDocument address = accountDocument.addresses.documents[index] as AddressDocument;
                if ((address.primaryaddress.Value != null) && (address.primaryaddress.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainAdress = true;
                }
            }
            if ((!hasMainAdress) && (accountDocument.addresses.documents.Count > 0))
            {
                AddressDocument address = accountDocument.addresses.documents[0] as AddressDocument;
                address.primaryaddress.Value = "true";
            }

            #endregion postal adresses

            if (GuidIsNullOrEmpty(feedEntry.UUID))
            {
                accountDocument.Id = feedEntry.Key;
            }
            else
            {
                accountDocument.CrmId = feedEntry.UUID.ToString();
                accountDocument.Id    = GetLocalId(feedEntry.UUID);
            }

            if (feedEntry.IsPropertyChanged("currency"))
            {
                accountDocument.currencyid.Value = feedEntry.currency;
            }


            #region emails
            accountDocument.emails = new EmailsDocumentCollection();
            if (feedEntry.emails != null)
            {
                foreach (EmailFeedEntry emailEntry in feedEntry.emails.Entries)
                {
                    EmailDocument emailDocument = _emailAdressTransformation.GetTransformedDocument(emailEntry);
                    accountDocument.emails.Add(emailDocument);
                }
            }
            #endregion

            if (feedEntry.IsPropertyChanged("name"))
            {
                accountDocument.name.Value = feedEntry.name;
            }

            // ????? document.onhold

            #region contacts
            accountDocument.people = new PeopleDocumentCollection();
            if (feedEntry.contacts != null)
            {
                foreach (ContactFeedEntry contact in feedEntry.contacts.Entries)
                {
                    PersonDocument person = _contactTransformation.GetTransformedDocument(contact);
                    accountDocument.people.Add(person);
                }
            }
            bool hasMainPerson = false;
            for (int index = 0; index < accountDocument.people.documents.Count; index++)
            {
                PersonDocument person = accountDocument.people.documents[index] as PersonDocument;
                if ((person.primaryperson.Value != null) && (person.primaryperson.Value.ToString().Equals("true", StringComparison.InvariantCultureIgnoreCase)))
                {
                    hasMainPerson = true;
                }
            }
            if ((!hasMainPerson) && (accountDocument.people.documents.Count > 0))
            {
                PersonDocument person = accountDocument.people.documents[0] as PersonDocument;
                person.primaryperson.Value = "true";
            }
            #endregion

            #region phones
            accountDocument.phones = new PhonesDocumentCollection();
            if (feedEntry.phones != null)
            {
                foreach (PhoneNumberFeedEntry phoneNumberPayload in feedEntry.phones.Entries)
                {
                    PhoneDocument phone = _phoneNumberTransformation.GetTransformedDocument(phoneNumberPayload);
                    accountDocument.phones.Add(phone);
                }
            }
            #endregion

            if (feedEntry.IsPropertyChanged("customerSupplierFlag"))
            {
                accountDocument.customerSupplierFlag.Value = Enum.GetName(typeof(supplierFlagenum), feedEntry.customerSupplierFlag);
            }

            return(accountDocument);
        }
예제 #3
0
        public TradingAccountPayload GetTransformedPayload(AccountDocument document, out List <SyncFeedEntryLink> links)
        {
            links = new List <SyncFeedEntryLink>();
            TradingAccountPayload payload        = new TradingAccountPayload();
            tradingAccounttype    tradingAccount = new tradingAccounttype();

            tradingAccount.accountingType       = tradingAccountAccountingTypeenum.Unknown;
            tradingAccount.customerSupplierFlag = (document.customerSupplierFlag.IsNull) ? null : document.customerSupplierFlag.Value.ToString();
            tradingAccount.active = true;
            //tradingAccount.postalAddresses = new postalAddresstype[0]();
            //tradingAccount.contacts = new contacttype[0]();
            //tradingAccount.phones = new phoneNumbertype[0]();
            tradingAccount.deleted         = false;
            tradingAccount.deliveryContact = null;
            tradingAccount.deliveryMethod  = null;
            tradingAccount.deliveryRule    = false;
            //tradingAccount.emails = new emailtype[0]();
            tradingAccount.applicationID = document.Id;
            payload.SyncUuid             = GetUuid(document.Id, document.CrmId);
            payload.LocalID      = document.Id;
            tradingAccount.uuid  = payload.SyncUuid.ToString();
            tradingAccount.label = SupportedResourceKinds.tradingAccounts.ToString();
            tradingAccount.name  = (document.name.IsNull) ? null : document.name.Value.ToString();


            //Many more things should set to default values


            // adresses
            int adressCount = document.addresses.documents.Count;

            tradingAccount.postalAddresses = new postalAddresstype[adressCount];
            for (int index = 0; index < adressCount; index++)
            {
                List <SyncFeedEntryLink> addressLinks;
                AddressDocument          address = document.addresses.documents[index] as AddressDocument;
                PostalAddressPayload     postalAdressPayload;
                postalAdressPayload = _postalAdressTransformation.GetTransformedPayload(address, out addressLinks);
                tradingAccount.postalAddresses[index] = postalAdressPayload.PostalAddresstype;
                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.postalAddresses.ToString(), postalAdressPayload.LocalID),
                              "postalAddresses",
                              "postalAddresses[" + index.ToString() + "]",
                              postalAdressPayload.SyncUuid.ToString()));
            }

            //emails
            int emailsCount = document.emails.documents.Count;

            tradingAccount.emails = new emailtype[emailsCount];
            for (int index = 0; index < emailsCount; index++)
            {
                List <SyncFeedEntryLink> emailLinks;
                EmailDocument            email = document.emails.documents[index] as EmailDocument;
                EmailPayload             EmailPayload;
                EmailPayload = _emailAdressTransformation.GetTransformedPayload(email, out emailLinks);
                tradingAccount.emails[index] = EmailPayload.Emailtype;

                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.emails.ToString(), EmailPayload.LocalID),
                              "emails",
                              "emails[" + index.ToString() + "]",
                              EmailPayload.SyncUuid.ToString()));
            }


            //phones
            int phonesCount = document.phones.documents.Count;

            tradingAccount.phones = new phoneNumbertype[phonesCount];
            for (int index = 0; index < phonesCount; index++)
            {
                List <SyncFeedEntryLink> phoneLinks;
                PhoneDocument            phone = document.phones.documents[index] as PhoneDocument;
                PhoneNumberPayload       phoneNumberPayload;
                phoneNumberPayload           = _phoneNumberTransformation.GetTransformedPayload(phone, out phoneLinks);
                tradingAccount.phones[index] = phoneNumberPayload.PhoneNumbertype;

                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.phoneNumbers.ToString(), phoneNumberPayload.LocalID),
                              "phones",
                              "phones[" + index.ToString() + "]",
                              phoneNumberPayload.SyncUuid.ToString()));
            }

            //contacts
            int contactsCount = document.people.documents.Count;

            tradingAccount.contacts = new contacttype[contactsCount];
            for (int index = 0; index < contactsCount; index++)
            {
                List <SyncFeedEntryLink> contactLinks;
                PersonDocument           person = document.people.documents[index] as PersonDocument;
                ContactPayload           contactPayload;
                contactPayload = _contactTransformation.GetTransformedPayload(person, out contactLinks);
                tradingAccount.contacts[index] = contactPayload.Contacttype;
                links.Add(SyncFeedEntryLink.CreateRelatedLink(
                              Common.ResourceKindHelpers.GetSingleResourceUrl(
                                  _context.DatasetLink, SupportedResourceKinds.contacts.ToString(), contactPayload.LocalID),
                              "contacts",
                              "contacts[" + index.ToString() + "]",
                              contactPayload.SyncUuid.ToString()));
            }


            payload.TradingAccount = tradingAccount;

            SyncFeedEntryLink selfLink = SyncFeedEntryLink.CreateSelfLink(String.Format("{0}{1}('{2}')", _datasetLink, SupportedResourceKinds.tradingAccounts, document.Id));

            links.Add(selfLink);
            return(payload);
        }
        public TradingAccountFeedEntry GetTransformedPayload(AccountDocument document)
        {
            TradingAccountFeedEntry entry = new TradingAccountFeedEntry();

            entry.customerSupplierFlag = GetSupplierFlag(document.customerSupplierFlag);
            entry.active = true;

            entry.deleted      = false;
            entry.deliveryRule = false;

            entry.name = (document.name.IsNull) ? null : document.name.Value.ToString();

            #region addresses
            int adressCount = document.addresses.documents.Count;
            entry.postalAddresses    = new PostalAddressFeed();
            entry.postalAddresses.Id = GetSDataId(document.Id) + "/" + SupportedResourceKinds.postalAddresses.ToString();
            for (int index = 0; index < adressCount; index++)
            {
                AddressDocument        address           = document.addresses.documents[index] as AddressDocument;
                PostalAddressFeedEntry postalAdressEntry = _postalAdressTransformation.GetTransformedPayload(address);
                if (postalAdressEntry != null)
                {
                    entry.postalAddresses.Entries.Add(postalAdressEntry);
                }
            }
            #endregion

            #region emails
            int emailsCount = document.emails.documents.Count;
            entry.emails = new EmailFeed();
            for (int index = 0; index < emailsCount; index++)
            {
                EmailDocument  email      = document.emails.documents[index] as EmailDocument;
                EmailFeedEntry emailEntry = _emailAdressTransformation.GetTransformedPayload(email);
                entry.emails.Entries.Add(emailEntry);
            }
            #endregion


            #region phones
            int phonesCount = document.phones.documents.Count;
            entry.phones = new PhoneNumberFeed();
            for (int index = 0; index < phonesCount; index++)
            {
                PhoneDocument        phone            = document.phones.documents[index] as PhoneDocument;
                PhoneNumberFeedEntry phoneNumberEntry = _phoneNumberTransformation.GetTransformedPayload(phone);
                if (phoneNumberEntry != null)
                {
                    entry.phones.Entries.Add(phoneNumberEntry);
                }
            }
            #endregion

            #region contacts
            int contactsCount = document.people.documents.Count;
            entry.contacts = new ContactFeed();
            for (int index = 0; index < contactsCount; index++)
            {
                PersonDocument   person       = document.people.documents[index] as PersonDocument;
                ContactFeedEntry contactEntry = _contactTransformation.GetTransformedPayload(person);
                if (contactEntry != null)
                {
                    entry.contacts.Entries.Add(contactEntry);
                }
            }
            #endregion

            entry.currency = _config.CurrencyCode;
            SetCommonProperties(document, entry.name, entry);
            return(entry);
        }