Role Helper
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的更多相关文章
- jdbc的封装
package com.wjf.helper; import java.io.FileInputStream; import java.io.FileOutputStream; import java ...
- [ASP.NET MVC 小牛之路]13 - Helper Method
我们平时编程写一些辅助类的时候习惯用“XxxHelper”来命名.同样,在 MVC 中用于生成 Html 元素的辅助类是 System.Web.Mvc 命名空间下的 HtmlHelper,习惯上我们把 ...
- Helper Method
ASP.NET MVC 小牛之路]13 - Helper Method 我们平时编程写一些辅助类的时候习惯用“XxxHelper”来命名.同样,在 MVC 中用于生成 Html 元素的辅助类是 Sys ...
- [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 ...
- **CodeIgniter系列 添加filter和helper
filter: 使用CI的hooks来实现filter. 1.在system/application/config/config.php中,把enable_hooks的值改为TRUE $config[ ...
- [C#] 简单的 Helper 封装 -- RegularExpressionHelper
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 解决: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 ...
- handlebars自定义helper的写法
handlebars相对来讲算一个轻量级.高性能的模板引擎,因其简单.直观.不污染HTML的特性,我个人特别喜欢.另一方面,handlebars作为一个logicless的模板,不支持特别复杂的表达式 ...
- 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": { " ...
随机推荐
- 【转】】Vue项目部署tomcat,刷新报错404解决办法
转自[https://blog.csdn.net/g631521612/article/details/82835518] 解决方式: - 在tocmat的webapps下的项目中创建WEB-INF文 ...
- 企业级Nginx基于虚拟主机别名的设置
生活中访问www.baidu.com和baidu.com是一个效果,同理也可以用rewrite 301跳转的思路(多发了一次请求过去)配置nginx.conf文件或者include里面的引用的文件,道 ...
- 初始python(一)
一.python特性概要 1. python是解释性脚本语言. 2. python特性总结 2.1 字节码 2.2 动态语义 在赋值是确定数据类型 2.3 缩进(4个空格) 3. python定义编码 ...
- August 02nd 2017 Week 31st Wednesday
Love means never having to say you are sorry. 爱就是永远不必说对不起. If there is ture love, you will never do ...
- python29 excel写模块xlwt
xlwt模块用于新建excel文件并写入数据. 安装 pip install xlwt 简单使用 import xlwt from datetime import datetime #样式 style ...
- 纯css3跑马灯demo
我们写跑马灯一般都是用js控制定时器不断循环产生,但是定时器消耗比较大,特别是程序中很多用到定时器的时候,感觉有的时候比较卡.但是css3样式一般不会.这里主要的思路就是用css3代替js定时器实现一 ...
- python中的Lock
#Lock.py from multiprocessing import Process,Lock import os def f(l,i): l.acquire() print('hello wor ...
- BZOJ1016:[JSOI2008]最小生成树计数(最小生成树,DFS)
Description 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不同的最小生成树.(如果两颗最小生成树中至少有一条边不同,则这两个最小生成树就是不同的 ...
- 【node.js】REPL(交互式解释器)
Node 自带了交互式解释器,可以执行以下任务: 读取 - 读取用户输入,解析输入了Javascript 数据结构并存储在内存中. 执行 - 执行输入的数据结构 打印 - 输出结果 循环 - 循环操作 ...
- .net發送郵件
using System; using System.Collections.Generic; using System.Linq; using System.Net.Mail; using Syst ...