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": { " ...
随机推荐
- oracle表名、字段名大小写问题。
oracle 表名 .字段名 默认不区分大小写,除非建表语句中带双引号 如CREATE TABLE "TableName"("ID" number). CRE ...
- asp.net的HTTP请求处理过程
1.asp.net的HTTP请求处理过程 说明: (1).客户端浏览器向服务器发出一个http请求,此请求会被inetinfo.exe进程截获,然后转交给aspnet_isapi.dll进程,接着它又 ...
- 乘风破浪:LeetCode真题_013_Roman to Integer
乘风破浪:LeetCode真题_013_Roman to Integer 一.前言 上一节我们讨论了如何把阿拉伯数字转换成罗马数字,现在我们需要思考一下如何把罗马数字转换成阿拉伯数字,其实我们仔细观擦 ...
- 在ASP.NET MVC中,使用Bundle来打包压缩js和css(转)
转自:http://www.cnblogs.com/xwgli/p/3296809.html 在ASP.NET MVC4中(在WebForm中应该也有),有一个叫做Bundle的东西,它用来将js和c ...
- mysql_fetch_row,mysql_fetch_array,mysql_fetch_object,mysql_fetch_assoc
php从mysql中访问数据库并取得数据,取得结果的过程中用到好几个类似的方法,区别及用法值得区分一下,看下面的代码 代码如下: <?php $link=mysql_connect('local ...
- Android Volley源码分析及扩展
转载请标明出处: http://www.cnblogs.com/why168888/p/6681232.html 本文出自:[Edwin博客园] Volley 介绍 Android系统中主要提供了两种 ...
- less使用总结
15年自学了 less ,可是一直没用,就忘记了.后来抱着提高 css 开发速度的目的,又去学习了 less ,学完马上用,效果立竿见影,记得也牢了.刚开始学习前,我们总会问自己一个问题,学习它有什么 ...
- 31、springboot与任务
异步任务 测试如下: 进行等待三秒在进行应答 @Service public class AsynService { public void hello(){ try { Thread.sleep() ...
- js replace替换一段文本中所有的相同字符
在html<textarea>标签中回车换行的代码是: \n,html编辑器的回车换行是:\r\n或是\n. 下图是存入后台的<textarea>的文本,需要在页面上显示出来, ...
- Eclipse中修改git地址、用户、密码
1. 修改Url Window > Preferences > Team > Git > Configuration > Repository Settings 2. 修 ...