Exemplo n.º 1
0
        /// <summary>
        /// A basic add example
        /// </summary>
        /// <param name="orgCode">The org code of both accounts</param>
        /// <param name="masterAccountCode">The account code of the parent account</param>
        /// <param name="subordinateAccountCode">The account code of the child account</param>
        /// <param name="relationshipType">This is the code for the relationship type of the relationship.  This is the foreign key code from the EV876 master table</param>
        /// <param name="eventSalesDesignation">Set at least one designation and whether if it's Primary or Secondary.  NOTE: Both the master and subordinate account should belong to that designation.  You can use the RelationshipDesignationStatus class to set the designation (ex: UngerboeckSDKPackage.USISDKConstants.RelationshipDesignationStatus.Primary)</param>
        public RelationshipsModel Add(string orgCode, string masterAccountCode, string subordinateAccountCode, string relationshipType, string eventSalesDesignation)
        {
            var myRelationship = new RelationshipsModel
            {
                MasterOrganizationCode      = orgCode,
                MasterAccountCode           = masterAccountCode,
                SubordinateAccountCode      = subordinateAccountCode,
                RelationshipType            = relationshipType,
                SubordinateOrganizationCode = orgCode, //Note that multi-organization relationships aren't yet supported by the API.
                EventSalesDesignation       = eventSalesDesignation
            };

            return(APIUtil.AddRelationship(USISDKClient, myRelationship));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Convert EntitySchema to JSON
        /// </summary>
        /// <param name="th"></param>
        /// <returns></returns>
        public static string ToJSON(this RelationshipsModel th)
        {
            if (th.RelationshipsOneToMany != null)
            {
                th.RelationshipsOneToMany = th.RelationshipsOneToMany.ToList().OrderByDescending(o => o.Count).ToArray();
            }

            if (th.RelationshipsManyToMany != null)
            {
                th.RelationshipsManyToMany = th.RelationshipsManyToMany.ToList().OrderByDescending(o => o.Count).ToArray();
            }

            using (MemoryStream memoryStream = new MemoryStream())
            {
                DataContractJsonSerializer serializer = new DataContractJsonSerializer(th.GetType());
                serializer.WriteObject(memoryStream, th);
                return(Encoding.UTF8.GetString(memoryStream.ToArray()));
            }
        }
Exemplo n.º 3
0
        public RelationshipsModel RetrieveRelationships(string oneToMany, string manyToMany)
        {
            //Define a contract to return
            RelationshipsModel entitySchemaModel = new RelationshipsModel();

            entitySchemaModel.RecordId   = $"S360-{this.Record.Id.ToString()}";
            entitySchemaModel.LastUpdate = DateTime.UtcNow.ToString("G");

            //Request all entity relationships
            RetrieveEntityRequest request = new RetrieveEntityRequest()
            {
                LogicalName   = this.Record.LogicalName,
                EntityFilters = EntityFilters.Relationships
            };
            RetrieveEntityResponse response = (RetrieveEntityResponse)ServiceAdmin.Execute(request);

            if (response != null)
            {
                entitySchemaModel.RelationshipsOneToMany  = GetOneToManyRelationships(response, oneToMany);
                entitySchemaModel.RelationshipsManyToMany = GetManyToManyRelationships(response, manyToMany);
            }

            return(entitySchemaModel);
        }