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": { " ...
随机推荐
- sql server 查询分析器中表名无效,有红线,其实是这张表的
ctrl+shift+R 就OK了,就是刷新本地缓存.
- Oralce 序列
序列: 是oacle提供的用于产生一系列唯一数字的数据库对象. l 自动提供唯一的数值 l 共享对象 l 主要用于提供主键值 l 将序列值装入内存可以提高访问效率 创建序列: 1. 要有创建 ...
- CentOS随笔 - 3.CentOS7安装Oracle 11g xe
前言 转帖请注明出处: http://www.cnblogs.com/Troy-Lv5/ 由于手上很多项目都是采用Oracle在进行开发, 所以安装Oracle成为必然. 当然有朋友会想为什么不安装1 ...
- SSM框架——实现分页和搜索分页
登录|注册 在路上 在路上,要懂得积累:在路上,要学会放下:我在路上!Stay hungry,Stay foolish. 目录视图 摘要视图 订阅 [公告]博客系统优化升级 ...
- CALayer的additive属性解析
CALayer的additive属性解析 效果: 源码:https://github.com/RylanJIN/ShareOfCoreAnimation // // CAPartAViewContro ...
- SQL insert语句中插入带有特殊符号
1.插入数据库字符串中海油单引号,需要转义处理,例如插入“I‘m OK!” SQL语句: INSERT INTO tableTest(FileTXT) VALUES('I''m OK!') 2.如果S ...
- C# 冒泡排序法、插入排序法、选择排序法
冒泡排序法 是数组等线性排列的数字从大到小或从小到大排序. 以从小到大排序为例. 数据 11, 35, 39, 30, 7, 36, 22, 13, 1, 38, 26, 18, 12, 5, 45, ...
- 用AutoHotkey实现Excel从表B提取匹配数据到表A
说明:为表述方便,待填的表为[表A],资料库的表称为[表B].该工具可以快捷地从[表B]中提取相关数据到[表A],顺序和列可自定义. 使用方法:1.打开[ExcelGetFromB.exe](如要打开 ...
- 省事之通用Makefile模版
现在编译方案都偏爱使用cmake解决问题,这两条做unity插件,还是用Makefile,居然忘得光光,好记性不如烂笔头. 后面,翻箱倒柜找到以前为炼金术写的Makefiel,发现还真是挺好用,贴出来 ...
- lua垃圾回收之空表
故事背景: 自己手动手写的一个lua外部库luaopen_xxx,采用了tolua++1.0.93,编译后得到xxx.dll,当在luajit中require 'xxx'后是正常的,但如果运行环境换成 ...