using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk.Messages;
using System.Collections.Generic; /// <summary>
/// 安全角色
/// </summary>
public class RoleHelper
{
public static readonly string entityName = "role";
public Guid roleId = Guid.Empty; /// <summary>
/// 创建安全角色
/// </summary>
/// <param name="service">服务</param>
/// <param name="name">角色名称</param>
/// <param name="unitId">业务部门</param>
public void Create(IOrganizationService service, string name, Guid unitId)
{
Entity en = new Entity() { LogicalName = entityName };
en["name"] = name;
en["businessunitid"] = new EntityReference() { LogicalName = "businessunit", Id = unitId };
roleId = service.Create(en);
} /// <summary>
/// 修改安全角色
/// </summary>
/// <param name="service">服务</param>
/// <param name="name">角色名称</param>
/// <param name="unitId">业务部门</param>
public void Update(IOrganizationService service, string name, Guid unitId)
{
Entity en = new Entity() { LogicalName = entityName, Id = roleId };
en["name"] = name;
en["businessunitid"] = new EntityReference() { LogicalName = "businessunit", Id = unitId };
service.Update(en);
} /// <summary>
/// 给安全角色添加权限
/// </summary>
/// <param name="service">服务</param>
/// <param name="businessUnitId">业务部门id</param>
/// <param name="privilegeId">权限id</param>
public void AddPrivilegesRole(IOrganizationService service, Guid businessUnitId, Guid privilegeId)
{
AddPrivilegesRoleRequest request = new AddPrivilegesRoleRequest();
request.RoleId = roleId;
RolePrivilege rp = new RolePrivilege();
//Basic: 1/4,Local : 1/2,Deep : 3/4,Global: 4/4 组织
rp.Depth = PrivilegeDepth.Basic;
//权限
rp.PrivilegeId = privilegeId;
//业务部门
rp.BusinessUnitId = businessUnitId;
//权限
request.Privileges = new RolePrivilege[] { rp }; service.Execute(request);
} /// <summary>
/// 给安全角色移除权限
/// </summary>
/// <param name="service">服务</param>
/// <param name="privilergeId">安全角色</param>
public void RemovePrivilegeRole(IOrganizationService service, Guid privilergeId)
{
RemovePrivilegeRoleRequest roleRequest = new RemovePrivilegeRoleRequest();
roleRequest.RoleId = roleId;
roleRequest.PrivilegeId = privilergeId;
service.Execute(roleRequest);
} /// <summary>
/// 安全角色替换权限(删除以前的角色,添加现有的角色)
/// </summary>
/// <param name="service">服务</param>
/// <param name="businessUnitId">业务部门id</param>
/// <param name="privilegeId">权限id</param>
public void ReplacePrivilegeRpole(IOrganizationService service, Guid businessUnitId, Guid privilegeId)
{
ReplacePrivilegesRoleRequest roleRequest = new ReplacePrivilegesRoleRequest();
roleRequest.RoleId = roleId;
RolePrivilege rp = new RolePrivilege();
//Basic: 1/4,Local : 1/2,Deep : 3/4,Global: 4/4 组织
rp.Depth = PrivilegeDepth.Basic;
//权限
rp.PrivilegeId = privilegeId;
//业务部门
rp.BusinessUnitId = businessUnitId;
//权限
roleRequest.Privileges = new RolePrivilege[] { rp }; service.Execute(roleRequest);
} /// <summary>
/// 检索分派给指定角色的权限
/// </summary>
/// <param name="service">服务</param>
public void SearchPrivilegeRole(IOrganizationService service)
{
RetrieveRolePrivilegesRoleRequest request = new RetrieveRolePrivilegesRoleRequest();
request.RoleId = roleId; ReplacePrivilegesRoleResponse response = (ReplacePrivilegesRoleResponse)service.Execute(request);
if (response != null && response.Results != null)
{
ParameterCollection result = response.Results;
}
} /// <summary> ///
/// 删除安全角色 ///
/// </summary> ///
/// <param name="service">服务</param>
public void Delete(IOrganizationService service) { service.Delete(entityName, roleId); }
}

Role Helper的更多相关文章

  1. jdbc的封装

    package com.wjf.helper; import java.io.FileInputStream; import java.io.FileOutputStream; import java ...

  2. [ASP.NET MVC 小牛之路]13 - Helper Method

    我们平时编程写一些辅助类的时候习惯用“XxxHelper”来命名.同样,在 MVC 中用于生成 Html 元素的辅助类是 System.Web.Mvc 命名空间下的 HtmlHelper,习惯上我们把 ...

  3. Helper Method

    ASP.NET MVC 小牛之路]13 - Helper Method 我们平时编程写一些辅助类的时候习惯用“XxxHelper”来命名.同样,在 MVC 中用于生成 Html 元素的辅助类是 Sys ...

  4. [Windows Azure] Building the web role for the Windows Azure Email Service application - 3 of 5

    Building the web role for the Windows Azure Email Service application - 3 of 5. This is the third tu ...

  5. **CodeIgniter系列 添加filter和helper

    filter: 使用CI的hooks来实现filter. 1.在system/application/config/config.php中,把enable_hooks的值改为TRUE $config[ ...

  6. [C#] 简单的 Helper 封装 -- RegularExpressionHelper

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. 解决:win10_x64 VMware Workstation and Hyper-V are not compatible. Remove the Hyper-V role from the system before running VMware Workstation

    bcdedit /set hypervisorlaunchtype off A reboot of of the Windows OS is necessary  必须重启才能生效   To enab ...

  8. handlebars自定义helper的写法

    handlebars相对来讲算一个轻量级.高性能的模板引擎,因其简单.直观.不污染HTML的特性,我个人特别喜欢.另一方面,handlebars作为一个logicless的模板,不支持特别复杂的表达式 ...

  9. Encountered an unexpected error when attempting to resolve tag helper directive '@addTagHelper' with value '"*, Microsoft.AspNet.Mvc.TagHelpers"'

    project.json 配置: { "version": "1.0.0-*", "compilationOptions": { " ...

随机推荐

  1. Jmeter入门(一)————线程组配置

    线程组相当于有多个用户,同时去执行相同的一批次任务.每个线程之间都是隔离的,互不影响的.一个线程的执行过程中,操作的变量,不会影响其他线程的变量值. Delay Thread creation unt ...

  2. 中间件(WAS、WMQ)运维 9个常见难点解析

    本文由社区中间件达人wangxuefeng266.ayy216226分享整理,包括WAS.WMQ在安装.巡检.监控.优化过程中的常见难点. 安装 1.was 负载均衡的机制的粘连性,was负载均衡异常 ...

  3. PHPStorm/webstorm/PyCharm tips

    phpstorm对于使用PHP开发web的人员来说,是一个非常不错的编辑开发IDE,以前用过sublime,但是相比于storm,sublime在浏览legacy代码,类代码编辑方面明显要逊色不少.同 ...

  4. java笔记--正则表达式的运用(包括电话,邮箱验证等)

    正则表达式 --如果朋友您想转载本文章请注明转载地址"http://www.cnblogs.com/XHJT/p/3877402.html "谢谢-- 正则表达式符号:" ...

  5. August 26th 2017 Week 34th Saturday

    Love means finding the beauty in someone's imperfections. 爱情就是在那个人的不完美中找到美. Our mate isn't actually ...

  6. August 05th 2017 Week 31st Saturday

    All endings are beginnings, we just don't know it at the time. 所有的结局都是新的开始,只是当时我们不知道而已. Several mont ...

  7. January 11 2017 Week 2nd Wednesday

    One always has time enough, if one will apply it well. 如果你能好好地利用,你总有足够的时间. If you always feel that y ...

  8. Python 执行命令行操作。

    os.system os.popen() commands.getstatusoutput(cmd) (status, output) = commands.getstatusoutput('cat ...

  9. 使用SN.exe对.Net生成的程序集进行签名

    CLR用数字签名的方式防止程序集发布后被人篡改,也可以确定发布人,这个方法就是使用公/私钥对,然后对程序集所有模块取一个哈希生成一个数字签名放在程序集的元数据中. 1.创建公/私钥对     创建公/ ...

  10. pip-修改为国内镜像源

    pip 常用命令 pip install ./downloads/SomePackage-1.0.4.tar.gz pip install http://my.package.repo/SomePac ...