当前位置: 首页>>代码示例>>C#>>正文


C# IOrganizationService.Disassociate方法代码示例

本文整理汇总了C#中IOrganizationService.Disassociate方法的典型用法代码示例。如果您正苦于以下问题:C# IOrganizationService.Disassociate方法的具体用法?C# IOrganizationService.Disassociate怎么用?C# IOrganizationService.Disassociate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOrganizationService的用法示例。


在下文中一共展示了IOrganizationService.Disassociate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssociateDissassociateSecurityRoles

        /// <summary>
        ///     Associates the dissassociate security roles.
        /// </summary>
        /// <param name="crmService">The CRM service.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <param name="associateRecords">if set to <c>true</c> [associate records].</param>
        public static void AssociateDissassociateSecurityRoles(IOrganizationService crmService, string roleName,
            bool associateRecords)
        {
            var roles = RetrieveMultipleByEntityName(crmService, EntityName.role, true);
            var systemUserRoles = RetrieveMultipleByEntityName(crmService, EntityName.systemuserroles);

            var systemUsers = RetrieveMultipleByEntityName(crmService, EntityName.systemuser, true);

            foreach (var user in systemUsers)
            {
                var tempRoleId =
                    roles.FirstOrDefault(
                        r =>
                            string.Compare((string) r.Value[role.name], roleName, StringComparison.OrdinalIgnoreCase) ==
                            0
                            && ((EntityReference) r.Value[role.businessunitid]).Id ==
                            ((EntityReference) user.Value[systemuser.businessunitid]).Id).Key;
                try
                {
                    var isExists = systemUserRoles.Any(c => (Guid) c.Value[systemuserroles.roleid] == tempRoleId
                                                            &&
                                                            (Guid) c.Value[systemuserroles.systemuserid] == user.Key);
                    if (associateRecords && !isExists)
                    {
                        "associating role {0} with user {1}".TraceVerbose(tempRoleId, user.Key);
                        crmService.Associate(
                            EntityName.systemuser,
                            user.Key,
                            new Relationship("systemuserroles_association"),
                            new EntityReferenceCollection
                            {
                                new EntityReference(EntityName.role, tempRoleId)
                            }
                            );
                        "association successful".TraceSuccess();
                    }
                    else if (!associateRecords && isExists)
                    {
                        "Disassociating role {0} with user {1}".TraceVerbose(tempRoleId, user.Key);
                        crmService.Disassociate(
                            EntityName.systemuser,
                            user.Key,
                            new Relationship("systemuserroles_association"),
                            new EntityReferenceCollection
                            {
                                new EntityReference(EntityName.role, tempRoleId)
                            }
                            );
                        "Disassociation successful".TraceSuccess();
                    }
                }
                catch (FaultException<OrganizationServiceFault> orgex)
                {
                    orgex.Message.TraceError(orgex);
                }
            }
        }
开发者ID:asifulm,项目名称:xrmdiff,代码行数:63,代码来源:XrmHelperAndUtilityFunctions.cs

示例2: Run

        /// <summary>
        /// Create and configure the organization service proxy.
        /// Create a team, a queue and a role.
        /// Add read queue privileges to the role.
        /// Assign the role to the team so that they can read the queue.
        /// Assign the queue to the team.
        /// Optionally delete any entity records that were created for this sample.
        // </summary>
        /// <param name="serverConfig">Contains server connection information.</param>
        /// <param name="promptForDelete">When True, the user will be prompted to delete all
        /// created entities.</param>
        public void Run(ServerConnection.Configuration serverConfig, bool promptForDelete)
        {
            try
            {

                // Connect to the Organization service. 
                // The using statement assures that the service proxy will be properly disposed.
                using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri, serverConfig.HomeRealmUri,
                                                                     serverConfig.Credentials, serverConfig.DeviceCredentials))
                {
                    // This statement is required to enable early-bound type support.
                    _serviceProxy.EnableProxyTypes();

                    _service = (IOrganizationService)_serviceProxy;

                    // Call the method to create any data that this sample requires.
                    CreateRequiredRecords();

                    //<snippetAssociateDisassociate1>
                    // Associate the accounts to the contact record.

                    // Create a collection of the entities that will be 
                    // associated to the contact.
                    EntityReferenceCollection relatedEntities = new EntityReferenceCollection();
                    relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account1Id));
                    relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account2Id));
                    relatedEntities.Add(new EntityReference(Account.EntityLogicalName, _account3Id));

                    // Create an object that defines the relationship between the contact and account.
                    Relationship relationship = new Relationship("account_primary_contact");


                    //Associate the contact with the 3 accounts.
                    _service.Associate(Contact.EntityLogicalName, _contactId, relationship,
                        relatedEntities);

                    Console.WriteLine("The entities have been associated.");

                    //Disassociate the records.
                    _service.Disassociate(Contact.EntityLogicalName, _contactId, relationship,
                        relatedEntities);

                    //</snippetAssociateDisassociate1>

                    Console.WriteLine("The entities have been disassociated.");

                    DeleteRequiredRecords(promptForDelete);
                }
            }

            // Catch any service fault exceptions that Microsoft Dynamics CRM throws.
            catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>)
            {
                // You can handle an exception here or pass it back to the calling method.
                throw;
            }
        }
开发者ID:cesugden,项目名称:Scripts,代码行数:68,代码来源:AssociateDisassociate.cs

示例3: Invoke_Disassociate

 public virtual void Invoke_Disassociate(IOrganizationService service)
 {
     // Act
     service.Disassociate(string.Empty, Guid.Empty, new Relationship(), new EntityReferenceCollection());
 }
开发者ID:Innofactor,项目名称:CUTE,代码行数:5,代码来源:ServiceTestCases.cs


注:本文中的IOrganizationService.Disassociate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。