The AccountEntity presents an account object of the application in the integration space. The entity supports: - GetDocument, GetDocumentTemplate - Insert, Update and Delete verb (to support execute transcation) - FillChangeLog and FillAll (to Support getChangelog and getAll)
상속: Sage.Integration.Northwind.Application.Base.EntityBase
        public new Sage.Common.Syndication.FeedEntry GetFeedEntry(string id)
        {
            PostalAddressFeedEntry result;

            Account account = new Account();
            Identity identity = new Identity(account.EntityName, id);
            AccountDocument accountDocument = (AccountDocument)_entity.GetDocument(identity, _emptyToken, _context.Config);

            if ((accountDocument.LogState == LogState.Deleted)
                    || (accountDocument.addresses.documents.Count == 0))
            {
                PostalAddressFeedEntry deletedPayload = new PostalAddressFeedEntry();
                deletedPayload.UUID = GetUuid(id);
                deletedPayload.IsDeleted = true;
                return deletedPayload;
            }

            Document document = accountDocument.addresses.documents[0];

            result = (PostalAddressFeedEntry)GetTransformedPayload(document);

            string taUuid = GetTradingAccountUuid(accountDocument.Id);

            #warning no reference for trading accounts exists in the contract

            return result;
        }
 public PostalAddressWrapper(RequestContext context)
     : base(context, SupportedResourceKinds.postalAddresses)
 {
     _entity = new Account();
     _transformation = TransformationFactory.GetTransformation<ITransformation<AddressDocument, PostalAddressPayload>>
         (SupportedResourceKinds.postalAddresses, context);
     _tradingAccountUuidPayloadPath = _resourceKind.ToString() + "/" + SupportedResourceKinds.tradingAccounts.ToString();
 }
예제 #3
0
 public ContactWrapper(RequestContext context)
     : base(context, SupportedResourceKinds.contacts)
 {
     _entity = new Account();
     _transformation = TransformationFactory.GetTransformation<ITransformation<PersonDocument, ContactPayload>>
         (SupportedResourceKinds.contacts, context);
     _tradingAccountUuidPayloadPath = _resourceKind.ToString() + "/" + SupportedResourceKinds.tradingAccounts.ToString();
 }
예제 #4
0
 public PhoneNumberWrapper(RequestContext context)
     : base(context, SupportedResourceKinds.phoneNumbers)
 {
     _entity = new Account();
     _transformation = TransformationFactory.GetTransformation<ITransformation<PhoneDocument, PhoneNumberPayload>>
         (SupportedResourceKinds.phoneNumbers, context);
     _tradingAccountUuidPayloadPath = _resourceKind.ToString() + "/" + SupportedResourceKinds.tradingAccounts.ToString();
 }
        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;
            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 SyncFeedEntry GetFeedEntry(string id)
        {
            SyncFeedEntry result = new SyncFeedEntry();
            result.Payload = PayloadFactory.CreatePayload(_resourceKind);

            Identity identity;
            AccountDocument accountDocument;
            Account account = new Account();
            identity = new Identity(account.EntityName, id);
            accountDocument = (AccountDocument)_entity.GetDocument(identity, _emptyToken, _context.Config);
            if (accountDocument.LogState == LogState.Deleted)
                return null;
            if (accountDocument.addresses.documents.Count == 0)
                return null;

            Document document = accountDocument.addresses.documents[0];
            List<SyncFeedEntryLink> links;
            result.Payload = GetTransformedPayload(document, out links);

            string taUuid = GetTradingAccountUuid(accountDocument.Id);
            if (!String.IsNullOrEmpty(taUuid))
            {
                SyncFeedEntryLink tradingAccountLink = SyncFeedEntryLink.CreateRelatedLink(
                    String.Format("{0}{1}('{2}')", _context.DatasetLink, SupportedResourceKinds.tradingAccounts.ToString(), accountDocument.Id),
                    SupportedResourceKinds.tradingAccounts.ToString(),
                     _tradingAccountUuidPayloadPath, taUuid);
                links.Add(tradingAccountLink);

            }
            result.SyncLinks = links;
            result.Id = String.Format("{0}{1}('{2}')", _context.DatasetLink, _resourceKind.ToString(), id);
            result.Title = String.Format("{0}: {1}", _resourceKind.ToString(), id);
            result.Updated = DateTime.Now;
            return result;
        }
예제 #8
0
 public TradingAccountWrapper(RequestContext context)
     : base(context, SupportedResourceKinds.tradingAccounts)
 {
     _entity = new Account();
     _transformation = TransformationFactory.GetTransformation<ITransformation<AccountDocument, TradingAccountPayload>>(SupportedResourceKinds.tradingAccounts, context);
 }
        public new Sage.Common.Syndication.FeedEntry GetFeedEntry(string id)
        {
            Sage.Common.Syndication.FeedEntry result;

            Identity identity;
            AccountDocument accountDocument;
            Account account = new Account();
            string accountId;
            if (id.EndsWith(Sage.Integration.Northwind.Application.API.Constants.PhoneIdPostfix))
                accountId = id.Substring(0, id.Length - Sage.Integration.Northwind.Application.API.Constants.PhoneIdPostfix.Length);
            else if (id.EndsWith(Sage.Integration.Northwind.Application.API.Constants.FaxIdPostfix))
                accountId = id.Substring(0, id.Length - Sage.Integration.Northwind.Application.API.Constants.FaxIdPostfix.Length);
            else
                return null;

            identity = new Identity(account.EntityName, accountId);

            accountDocument = (AccountDocument)_entity.GetDocument(identity, _emptyToken, _context.Config);

            if (accountDocument.LogState == LogState.Deleted)
                return null;
            if (accountDocument.addresses.documents.Count == 0)
                return null;
            Document document = null;
            foreach (Document phoneDoc in accountDocument.phones.documents)
            {
                if (phoneDoc.Id.Equals(id, StringComparison.InvariantCultureIgnoreCase))
                {
                    document = phoneDoc;
                    break;
                }
            }
            if (document == null)
                return null;

            result = GetTransformedPayload(document);
            return result;
        }
예제 #10
0
        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;
        }
예제 #11
0
        public override SyncFeedEntry GetFeedEntry(string id)
        {
            SyncFeedEntry result = new SyncFeedEntry();
            result.Payload = PayloadFactory.CreatePayload(_resourceKind);

            Identity identity;
            AccountDocument accountDocument;
            Account account = new Account();
            string accountId;
            if (id.EndsWith(Sage.Integration.Northwind.Application.API.Constants.PhoneIdPostfix))
                accountId = id.Replace(Sage.Integration.Northwind.Application.API.Constants.PhoneIdPostfix, "");
            else if (id.EndsWith(Sage.Integration.Northwind.Application.API.Constants.FaxIdPostfix))
                accountId = id.Replace(Sage.Integration.Northwind.Application.API.Constants.FaxIdPostfix, "");
            else
                return null;

            identity = new Identity(account.EntityName, accountId);

            accountDocument = (AccountDocument)_entity.GetDocument(identity, _emptyToken, _context.Config);

            if (accountDocument.LogState == LogState.Deleted)
                return null;
            if (accountDocument.addresses.documents.Count == 0)
                return null;
            Document document = null;
            foreach (Document phoneDoc in accountDocument.phones.documents)
            {
                if (phoneDoc.Id.Equals(id, StringComparison.InvariantCultureIgnoreCase))
                {
                    document = phoneDoc;
                    break;
                }
            }
            if (document == null)
                return null;

            List<SyncFeedEntryLink> links;
            result.Payload = GetTransformedPayload(document, out links);

            string taUuid = GetTradingAccountUuid(accountDocument.Id);
            if (!String.IsNullOrEmpty(taUuid))
            {
                SyncFeedEntryLink tradingAccountLink = SyncFeedEntryLink.CreateRelatedLink(
                    String.Format("{0}{1}('{2}')", _context.DatasetLink, SupportedResourceKinds.tradingAccounts.ToString(), accountDocument.Id),
                    SupportedResourceKinds.tradingAccounts.ToString(),
                     _tradingAccountUuidPayloadPath, taUuid);
                links.Add(tradingAccountLink);

            }
            result.SyncLinks = links;
            result.Id = String.Format("{0}{1}('{2}')", _context.DatasetLink, _resourceKind.ToString(), id);
            result.Title = String.Format("{0}: {1}", _resourceKind.ToString(), id);
            result.Updated = DateTime.Now;
            return result;
        }