public static readonly string entityName = "systemuser";

        public Guid userId = Guid.Empty;

/// <summary>

        /// 创建用户

        /// </summary>

        public void Create(IOrganizationService service)

        {

            Entity en = new Entity() { LogicalName = entityName };

            en["domainname"] = "test";

            en["fullname"] = "測试";

            userId = service.Create(en);

        }

/// <summary>

        /// 启用和停用用户

        /// </summary>

        /// <param name="service"></param>

        public void UpdateUserState(IOrganizationService service)

        {

            //启用用户

            UpdateState(entityName, userId, 0, -1, service);

            //停用用户

            UpdateState(entityName, userId, -1, -1, service);

        }

/// <summary>

        /// 加入和移除安全角色

        /// </summary>

        /// <param name="service">服务</param>

        /// <param name="roleId">安全角色</param>

        public void AddAndRemoveRole(IOrganizationService service,Guid roleId)

        {

            //加入安全角色

            AddConnection(service, "systemuserroles_association", new EntityReference() { LogicalName = "role", Id = roleId });

            //删除安全角色

            RemoveConnection(service, "systemuserroles_association", new EntityReference() { LogicalName = "role", Id = roleId });

        }

private void UpdateState(string enName, Guid id, int state, int status, IOrganizationService service)

        {

            SetStateRequest setState = new SetStateRequest()

            {

                EntityMoniker = new EntityReference()

                {

                    Id = id,

                    LogicalName = enName

                },

                State = new OptionSetValue(state),

                Status = new OptionSetValue(status)

            };

            service.Execute(setState);

        }

public void AddConnection(IOrganizationService service, string name, params EntityReference[] array)

        {

            Relationship ship = new Relationship(name);

            AssociateRequest request = new AssociateRequest();

            request.Relationship = ship;

            request.Target = new EntityReference() { LogicalName = entityName, Id = userId };

            request.RelatedEntities = new EntityReferenceCollection();

            request.RelatedEntities.AddRange(array);

            service.Execute(request);

        }

public void RemoveConnection(IOrganizationService service, string name, params EntityReference[] array)

        {

            Relationship ship = new Relationship(name);

            DisassociateRequest request = new DisassociateRequest();

            request.Relationship = ship;

            request.Target = new EntityReference() { LogicalName = entityName, Id = userId };

            request.RelatedEntities = new EntityReferenceCollection();

            request.RelatedEntities.AddRange(array);

            service.Execute(request);

        }

crm创建启用停用用户的更多相关文章

  1. 利用Oracle创建表空间和用户

    本文仅用于学习交流,商业用途请支持正版!转载请注明:http://www.cnblogs.com/mxbs/p/6217152.html 第一步,创建表空间 以SYS/sys账户和SYSDBA身份登录 ...

  2. Oracle创建表空间、用户、授权

    在创建好数据实例(数据库)好后的基础上,后续做的事情如下: ---创建表空间 create tablespace LIS2011DATA logging datafile 'd:\oracle\pro ...

  3. 如何创建一个有System用户权限的命令行

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:如何创建一个有System用户权限的命令行.

  4. oracle 11G创建表空间、用户、配置监听和TNS

    最近总在安装各种版本的oralce数据库做测试,11G,32位的,64位的,12C的,每次都折腾表空间,用户.tns啥的,这里记录下,再也不用现用现百度找了 一.创建表空间.用户  在plsql工具中 ...

  5. mongodb创建数据库和配置用户

    上一篇我们说了mongodb远程连接配置,今天给大家说下mongodb怎么创建数据库和配置用户,毕竟光有远程连接是不够的,我们还要上去操作和放数据的.   系统:centos 5.x   环境:mon ...

  6. Oracle数据库之创建表空间与用户

    Oracle数据库之创建表空间与用户 一.创建表空间 基本语法表述: CREATE TABLESPACE tablespace_name [DATAFILE datafile_spec1 [,data ...

  7. mongodb怎么创建数据库和配置用户

    mongodb怎么创建数据库和配置用户,远程连接是不够的,还要上去操作和放数据的. 系统:centos 5.x 环境:mongodb 1.安装mongodb 这步就不说了,大家自己去看Centos安装 ...

  8. oracle用命令创建表空间、用户,并为用户授权、收回权限。

    oracle中如何删除用户? Oracle中使用DROP USER来删除用户,如果使用DROP USER CASCADE那么用户的对象也同时被删除掉.为了达到删除用户的效果而又不影响对用户下的对象的使 ...

  9. Oracle创建表空间、用户管理、角色管理

    内容:Oracle创建表空间.用户管理.角色管理 1.用系统用户登录Oracle 默认的系统用户: sys/system.sysman.scott sys:权限最大,超级用户,可以完成所有任务, 默认 ...

随机推荐

  1. 有谁知道Delphi中"窗口"的创建过程?

      求助:有谁知道Delphi中窗口的创建过程,此“窗口”不仅仅指 TForm 类型, 还包括一般的窗口控件,如TButton,TEdit等等,希望有能够十分详细的运作 过程,比如说CreatPara ...

  2. bat如何批量删除指定部分文件夹名的文件夹

    @echo offfor /f "delims=" %%i in ('dir /s/b/ad 123*') do ( rd /s/q "%%~i")exit

  3. WSAEventSelect模型编程 详解

    转自:http://blog.csdn.net/wangjieest/article/details/7042108 WSAEventSelect模型编程 WSAEventSelect模型编程这个模型 ...

  4. Maven内置属性及使用

    Maven共有6类属性: 内置属性(Maven预定义,用户可以直接使用) ${basedir}表示项目根目录,即包含pom.xml文件的目录; ${version}表示项目版本; ${project. ...

  5. java数字转换成文字方法

    public class IntToSmallChineseNumber { public static String ToCH(int intInput) { String si = String. ...

  6. Caffe SSD AttributeError: 'module' object has no attribute 'LabelMap'

    caffe ssd 错误描述: AttributeError: 'module' object has no attribute 'LabelMap' SSD from caffe.proto imp ...

  7. verilog语法实例学习(2)

    Verilog中的信号类型 线网类型 线网类型表示一个或多个门或者其它类型的信号源驱动的硬件连线.如果没有驱动源,则线网的默认值为z.verilog中定义的线网类型有以下几种:     wire,tr ...

  8. scp命令:服务器间远程复制代码

    scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的.可能会稍微影响一下速度.当你服务器 ...

  9. [leetcode]Add Binary @ Python

    原题地址:https://oj.leetcode.com/problems/add-binary/ 题意: Given two binary strings, return their sum (al ...

  10. Combination Sum leetcode java

    题目: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C ...