Update() public method

The Update verb ammends an existing account and all subentities (Person, Email, Address, Phone) in the underlying data-store. The data as it should be stored is found in the parameter document. Should no account instance be found in the data-store that matches the id of the document, the transaction result will set accordingly.
public Update ( Document doc, NorthwindConfig config, List &result ) : void
doc Sage.Integration.Northwind.Application.Base.Document Document (incl. ID) containing the data to be stored
config NorthwindConfig The configuration object
result List
return void
        public override SdataTransactionResult Add(PayloadBase payload, List<SyncFeedEntryLink> links)
        {
            string accountUuid = "";
            SdataTransactionResult sdTrResult;
            PostalAddressPayload addressPayload = payload as PostalAddressPayload;

            if ((addressPayload.PostalAddresstype.primacyIndicatorSpecified) &&
                addressPayload.PostalAddresstype.primacyIndicator)
            {
                // is primary
            }
            else if (addressPayload.PostalAddresstype.type == postalAddressTypeenum.Correspondance)
            {
                // is also primary adress
            }
            else
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Only primary addresses suported";
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = SupportedResourceKinds.postalAddresses;
                sdTrResult.Uuid = StringToGuid(addressPayload.PostalAddresstype.uuid);
                return sdTrResult;

            }
            foreach (SyncFeedEntryLink link in links)
            {
                if ((!String.IsNullOrEmpty(link.PayloadPath)) &&
                    link.PayloadPath.Equals(_tradingAccountUuidPayloadPath,
                    StringComparison.InvariantCultureIgnoreCase))
                {
                    accountUuid = link.Uuid;
                    break;
                }
            }

            if (String.IsNullOrEmpty(accountUuid))
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Trading Account UUID was missing";
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = StringToGuid(addressPayload.PostalAddresstype.uuid);
                return sdTrResult;
            }

            string accountId = GetTradingAccountLocalId(accountUuid);

            if (String.IsNullOrEmpty(accountId))
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = String.Format("Trading Account UUID {0} was not linked", accountUuid);
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = StringToGuid(addressPayload.PostalAddresstype.uuid);
                return sdTrResult;
            }

            Account account = new Account();
            Identity accIdentity = new Identity(account.EntityName, accountId);
            AccountDocument accountDocument = account.GetDocument(
                accIdentity, _emptyToken, _context.Config) as AccountDocument;

            Document document = null;
            bool doAdd = false;
            if (accountDocument.addresses.documents.Count == 0)
            {
                document = GetTransformedDocument(payload, links);
                accountDocument.CrmId = GetTradingAccountUuid(document.Id);
                accountDocument.addresses.documents.Add(document);
                doAdd = true;
            }
            else
            {
                AddressDocument addressdocument = accountDocument.addresses.documents[0] as AddressDocument;
                if (addressdocument.address1.IsNull &&
                    addressdocument.address2.IsNull &&
                    addressdocument.address3.IsNull &&
                    addressdocument.address4.IsNull &&
                    addressdocument.City.IsNull)
                {
                    document = GetTransformedDocument(payload, links);
                    accountDocument.CrmId = GetTradingAccountUuid(document.Id);
                    accountDocument.addresses.documents[0] = document;
                    doAdd = true;
                }

            }
            if (!doAdd)
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Trading Account has already a primary address";
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = StringToGuid(addressPayload.PostalAddresstype.uuid);
                return sdTrResult;
            }

            List<TransactionResult> transactionResults = new List<TransactionResult>();
            account.Update(accountDocument, _context.Config, ref transactionResults);
            sdTrResult = Helper.GetSdataTransactionResult(transactionResults,
                _context.OriginEndPoint, SupportedResourceKinds.tradingAccounts);
            if (sdTrResult != null)
            {
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.HttpMessage = "POST";
            }
            return sdTrResult;
        }
        public override SdataTransactionResult Add(FeedEntry entry)
        {
            string accountUuid = string.Empty;
            SdataTransactionResult sdTrResult;
            ContactFeedEntry contactEntry = entry as ContactFeedEntry;

            if (contactEntry.primacyIndicator)
            {
                // is primary
            }
            else
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Only primary contacts supported";
                sdTrResult.HttpMethod = HttpMethod.POST;
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = SupportedResourceKinds.contacts;
                sdTrResult.Uuid = contactEntry.UUID.ToString();

                AttachDiagnosis(sdTrResult);
                return sdTrResult;

            }

            if(contactEntry.tradingAccount != null)
                accountUuid = contactEntry.tradingAccount.UUID.ToString();

            if (String.IsNullOrEmpty(accountUuid) || Guid.Empty.ToString() == accountUuid)
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Trading Account UUID was missing";
                sdTrResult.HttpMethod = HttpMethod.POST;
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = contactEntry.UUID.ToString();

                AttachDiagnosis(sdTrResult);
                return sdTrResult;
            }

            string accountId = GetTradingAccountLocalId(accountUuid);

            if (String.IsNullOrEmpty(accountId))
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = String.Format("Trading Account UUID {0} was not linked", accountUuid);
                sdTrResult.HttpMethod = HttpMethod.POST;
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = contactEntry.UUID.ToString();

                AttachDiagnosis(sdTrResult);
                return sdTrResult;
            }

            Account account = new Account();
            Identity accIdentity = new Identity(account.EntityName, accountId);
            AccountDocument accountDocument = account.GetDocument(
                accIdentity, _emptyToken, _context.Config) as AccountDocument;
            accountDocument.CrmId = accountUuid;

            Document document = null;
            bool doAdd = false;

            document = GetTransformedDocument(entry);
            if (accountDocument.people.documents.Count == 0)
            {
                accountDocument.people.documents.Add(document);
                doAdd = true;
            }
            else
            {
                PersonDocument personDocument = accountDocument.people.documents[0] as PersonDocument;
                if (personDocument.firstname.IsNull &&
                    personDocument.lastname.IsNull)
                {
                    accountDocument.people.documents[0] = document;
                    doAdd = true;
                }

            }
            if (!doAdd)
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Trading Account has already a primary contact";
                sdTrResult.HttpMethod = HttpMethod.POST;
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = contactEntry.UUID.ToString();

                AttachDiagnosis(sdTrResult);
                return sdTrResult;
            }

            List<TransactionResult> transactionResults = new List<TransactionResult>();
            account.Update(accountDocument, _context.Config, ref transactionResults);
            sdTrResult = GetSdataTransactionResult(transactionResults,
                _context.OriginEndPoint, SupportedResourceKinds.tradingAccounts);
            if (sdTrResult != null)
            {
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.HttpMessage = "POST";
            }
            return sdTrResult;
        }
        public override SdataTransactionResult Add(PayloadBase payload, List<SyncFeedEntryLink> links)
        {
            string accountUuid = "";
            SdataTransactionResult sdTrResult;
            PhoneNumberPayload phoneNumberPayload = payload as PhoneNumberPayload;
            bool isFax = false; ;
            bool isPhone = false;

            if (phoneNumberPayload.PhoneNumbertype.type.Equals("general", StringComparison.InvariantCultureIgnoreCase))
                isPhone = true;
            else if (phoneNumberPayload.PhoneNumbertype.type.Equals("fax", StringComparison.InvariantCultureIgnoreCase))
                isFax = true;

            else
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Only primary phonenumbers with type general and fax where accepted";
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = phoneNumberPayload.SyncUuid;
                return sdTrResult;
            }

            foreach (SyncFeedEntryLink link in links)
            {
                if ((!String.IsNullOrEmpty(link.PayloadPath)) &&
                    link.PayloadPath.Equals(_tradingAccountUuidPayloadPath,
                    StringComparison.InvariantCultureIgnoreCase))
                {
                    accountUuid = link.Uuid;
                    break;
                }
            }

            if (String.IsNullOrEmpty(accountUuid))
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Trading Account UUID was missing";
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = phoneNumberPayload.SyncUuid;
                return sdTrResult;
            }

            string accountId = GetTradingAccountLocalId(accountUuid);

            if (String.IsNullOrEmpty(accountId))
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = String.Format("Trading Account UUID {0} was not linked", accountUuid);
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = phoneNumberPayload.SyncUuid;
                return sdTrResult;
            }

            Account account = new Account();
            Identity accIdentity = new Identity(account.EntityName, accountId);
            AccountDocument accountDocument = account.GetDocument(
                accIdentity, _emptyToken, _context.Config) as AccountDocument;

            Document document = null;
            bool doAdd = false;

            document = GetTransformedDocument(payload, links);
            if (isPhone)
                document.Id = accountId + Sage.Integration.Northwind.Application.API.Constants.PhoneIdPostfix;
            if (isFax)
                document.Id = accountId + Sage.Integration.Northwind.Application.API.Constants.FaxIdPostfix;
            if (accountDocument.addresses.documents.Count == 0)
            {
                accountDocument.CrmId = GetTradingAccountUuid(document.Id);
                accountDocument.phones.documents.Add(document);
                doAdd = true;
            }
            else
            {
                for (int index = 0; index < accountDocument.phones.documents.Count; index++)
                {
                    if (accountDocument.phones.documents[index].Id.Equals(document.Id, StringComparison.InvariantCultureIgnoreCase))
                    {

                        if (((PhoneDocument)accountDocument.phones.documents[index]).number.IsNull)
                        {
                            doAdd = true;
                            accountDocument.phones.documents[index] = document;
                        }
                        break;
                    }

                }
            }
            if (!doAdd)
            {
                sdTrResult = new SdataTransactionResult();
                sdTrResult.HttpMessage = "Trading Account has already this primary phone type";
                sdTrResult.HttpMethod = "POST";
                sdTrResult.HttpStatus = System.Net.HttpStatusCode.Forbidden;
                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.Uuid = phoneNumberPayload.SyncUuid;
                return sdTrResult;
            }

            List<TransactionResult> transactionResults = new List<TransactionResult>();
            account.Update(accountDocument, _context.Config, ref transactionResults);
            sdTrResult = Helper.GetSdataTransactionResult(transactionResults,
                _context.OriginEndPoint, SupportedResourceKinds.tradingAccounts);
            if (sdTrResult != null)
            {

                sdTrResult.ResourceKind = _resourceKind;
                sdTrResult.HttpMessage = "POST";
            }
            return sdTrResult;
        }