Ejemplo n.º 1
0
        //</snippetWorkWithRelationships3>
        //<snippetWorkWithRelationships4>
        /// <summary>
        /// Determines whether two entities are eligible to participate in a relationship
        /// </summary>
        /// <param name="referencedEntity">Primary Entity</param>
        /// <param name="referencingEntity">Referencing Entity</param>
        /// <returns></returns>
        public bool EligibleCreateOneToManyRelationship(string referencedEntity,
                                                        string referencingEntity)
        {
            //Checks whether the specified entity can be the primary entity in one-to-many
            //relationship.
            CanBeReferencedRequest canBeReferencedRequest = new CanBeReferencedRequest
            {
                EntityName = referencedEntity
            };

            CanBeReferencedResponse canBeReferencedResponse =
                (CanBeReferencedResponse)_serviceProxy.Execute(canBeReferencedRequest);

            if (!canBeReferencedResponse.CanBeReferenced)
            {
                Console.WriteLine(
                    "Entity {0} can't be the primary entity in this one-to-many relationship",
                    referencedEntity);
            }

            //Checks whether the specified entity can be the referencing entity in one-to-many
            //relationship.
            CanBeReferencingRequest canBereferencingRequest = new CanBeReferencingRequest
            {
                EntityName = referencingEntity
            };

            CanBeReferencingResponse canBeReferencingResponse =
                (CanBeReferencingResponse)_serviceProxy.Execute(canBereferencingRequest);

            if (!canBeReferencingResponse.CanBeReferencing)
            {
                Console.WriteLine(
                    "Entity {0} can't be the referencing entity in this one-to-many relationship",
                    referencingEntity);
            }


            if (canBeReferencedResponse.CanBeReferenced == true &&
                canBeReferencingResponse.CanBeReferencing == true)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool CanCreateOneToManyRelationship <TOne, TMany>()
            where TOne : CrmPlusPlusEntity, new()
            where TMany : CrmPlusPlusEntity, new()
        {
            var canBeReferencedRequest = new CanBeReferencedRequest
            {
                EntityName = EntityNameAttribute.GetFromType <TOne>()
            };

            var canBeReferencingRequest = new CanBeReferencingRequest
            {
                EntityName = EntityNameAttribute.GetFromType <TMany>()
            };

            bool canBeReferenced  = ((CanBeReferencedResponse)service.Execute(canBeReferencedRequest)).CanBeReferenced;
            bool canBeReferencing = ((CanBeReferencingResponse)service.Execute(canBeReferencingRequest)).CanBeReferencing;

            return(canBeReferenced && canBeReferencing);
        }
Ejemplo n.º 3
0
        //</snippetWorkWithRelationships3>
        //<snippetWorkWithRelationships4>
        /// <summary>
        /// Determines whether two entities are eligible to participate in a relationship
        /// </summary>
        /// <param name="referencedEntity">Primary Entity</param>
        /// <param name="referencingEntity">Referencing Entity</param>
        /// <returns></returns>
        public bool EligibleCreateOneToManyRelationship(string referencedEntity, 
            string referencingEntity)
        {
            //Checks whether the specified entity can be the primary entity in one-to-many
            //relationship.
            CanBeReferencedRequest canBeReferencedRequest = new CanBeReferencedRequest
            {
                EntityName = referencedEntity
            };

            CanBeReferencedResponse canBeReferencedResponse =
                (CanBeReferencedResponse)_serviceProxy.Execute(canBeReferencedRequest);

            if (!canBeReferencedResponse.CanBeReferenced)
            {
                Console.WriteLine(
                    "Entity {0} can't be the primary entity in this one-to-many relationship", 
                    referencedEntity);
            }

            //Checks whether the specified entity can be the referencing entity in one-to-many
            //relationship.
            CanBeReferencingRequest canBereferencingRequest = new CanBeReferencingRequest
            {
                EntityName = referencingEntity
            };

            CanBeReferencingResponse canBeReferencingResponse =
                (CanBeReferencingResponse)_serviceProxy.Execute(canBereferencingRequest);

            if (!canBeReferencingResponse.CanBeReferencing)
            {
                Console.WriteLine(
                    "Entity {0} can't be the referencing entity in this one-to-many relationship", 
                    referencingEntity);
            }


            if (canBeReferencedResponse.CanBeReferenced == true
                && canBeReferencingResponse.CanBeReferencing == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }