Beispiel #1
0
        /// <summary>
        /// Constructs a link-entity chain from the <paramref name="fetch"/>
        /// </summary>
        /// <param name="customerToProductRelationshipNamesCollection">Collection of relationships that map from Customer to Product</param>
        /// <param name="fetch">Fetch used to construct link chain</param>
        /// <param name="filter">Filter to inject conditions into</param>
        /// <param name="contact">Contact EntityReference</param>
        /// <param name="account">Account EntityReference</param>
        /// <param name="owningCustomerType">Owning Customer Type</param>
        /// <param name="linkEntityAliasGenerator">Single instance to maintain alias postfix incrementation</param>
        /// <returns>Root link of the constructed chain</returns>
        private Link BuildLinksAndFilterChain(string[] customerToProductRelationshipNamesCollection,
                                              Fetch fetch, Filter filter, EntityReference contact, EntityReference account,
                                              OwningCustomerType owningCustomerType, LinkEntityAliasGenerator linkEntityAliasGenerator)
        {
            var rootLink    = new Link();
            var linkDetails = this.GetLinkDetails(customerToProductRelationshipNamesCollection, owningCustomerType);

            foreach (var linkDetail in linkDetails)
            {
                var innermostLink = GetInnermostLink(rootLink);

                var currentLinkDetailConnectsToAccountOrContact = (contact != null && (linkDetail.Entity1Name == "contact" || linkDetail.Entity2Name == "contact")) ||
                                                                  (account != null && (linkDetail.Entity1Name == "account" || linkDetail.Entity2Name == "account"));
                this.BuildLinksAndFilter(this.Portal.ServiceContext, linkDetail, fetch, innermostLink, filter, contact, account, currentLinkDetailConnectsToAccountOrContact, linkEntityAliasGenerator);
            }

            return(rootLink);
        }
Beispiel #2
0
        /// <summary>
        /// Constructs the <see cref="LinkDetails"/> collection that maps from specified <see cref="EntityPermissionScope"/> to Product
        /// </summary>
        /// <param name="contactToProductRelationshipNamesCollection">Collection of relationship names that map from specified <see cref="EntityPermissionScope"/> to Product</param>
        /// <param name="owningCustomerType"><see cref="EntityPermissionScope"/> of owning Customer</param>
        /// <returns>Collection of <see cref="LinkDetails"/> from specified <see cref="OwningCustomerType"/> to Product</returns>
        private IEnumerable <LinkDetails> GetLinkDetails(string[] contactToProductRelationshipNamesCollection, OwningCustomerType owningCustomerType)
        {
            // Specify the corresponding Customer schema name based on passed EntityPermissionScope
            var entityPermissionScopeName = owningCustomerType == OwningCustomerType.Account
                ? "account"
                : "contact";

            var linkDetailsCollection = new List <LinkDetails>();

            if (contactToProductRelationshipNamesCollection.Count() == 1)
            {
                linkDetailsCollection.Add(new LinkDetails("product", entityPermissionScopeName, contactToProductRelationshipNamesCollection[0], owningCustomerType));
            }
            else if (contactToProductRelationshipNamesCollection.Count() == 2)
            {
                // Retrieve Customer and Product metadata
                var customerMetadata = GetEntityMetadata(this.Portal.ServiceContext, entityPermissionScopeName);
                var productMetadata  = GetEntityMetadata(this.Portal.ServiceContext, "product");

                // Retrieve the intersecting entities schema name for the specified relationship name
                var customer2IntersectSchemaName = customerMetadata.OneToManyRelationships.FirstOrDefault(metadata => metadata.SchemaName == contactToProductRelationshipNamesCollection[0]);
                var product2IntersectSchemaName  = productMetadata.OneToManyRelationships.FirstOrDefault(metadata => metadata.SchemaName == contactToProductRelationshipNamesCollection[1]);

                // Ensure that the insersecting entity for the specified relationships match
                if (customer2IntersectSchemaName == null || product2IntersectSchemaName == null || product2IntersectSchemaName.ReferencingEntity != customer2IntersectSchemaName.ReferencingEntity)
                {
                    return(linkDetailsCollection);
                }

                // Add the specified LinkDetails to the collection
                linkDetailsCollection.Add(new LinkDetails("product", product2IntersectSchemaName.ReferencingEntity, contactToProductRelationshipNamesCollection[1]));
                linkDetailsCollection.Add(new LinkDetails(customer2IntersectSchemaName.ReferencingEntity, entityPermissionScopeName, contactToProductRelationshipNamesCollection[0], owningCustomerType));
            }

            return(linkDetailsCollection);
        }