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": { " ...
随机推荐
- Jmeter————监控服务器性能
1. 下载jmeter插件 上面2个是jmeter插件,第3个要放在监控的服务器中. 2. 解压压缩包 找到解压包中的JAR文件,并拷贝到jmeter的lib/ext目录下,这里下载的1.4版本的插件 ...
- Oracle 检查表的数据变动
本知识点仅适用于Oracle 9i以上的版本. 查看表的数据变动情况请使用SQL语句:select * from user_tab_modifications; user_tab_modificati ...
- [翻译] DoActionSheet
DoActionSheet https://github.com/donobono/DoActionSheet An replacement for UIActionSheet : block-bas ...
- Exchange 接收连接器(Client、Default)区别,OUtlook实际测试
CAS就是接收连接器(110,995): Server Config--Client Access:POP3 and IMAP4:POP3设置 HUB就是发送连接器(25,587) Server Co ...
- Effective C++(9) 构造函数调用virtual函数会发生什么
问题聚焦: 不要在构造函数和析构函数中调用virtual函数,因为这样的调用不会带来你预想的结果. 让我先来看一下在构造函数里调用一个virtual函数会发生什么结果 Demo class Trans ...
- ecshop hash登录 + wordpress mysql盲注字段
delete_cart_goods.php post id=a * sq_xfkjbd 暴库and(select 1 from(select count(*),concat((select (se ...
- calayer 的特殊属性整理
calayer: An object that manages image-based content and allows you to perform animations on that con ...
- python各种模块的使用
Pexpect模块:http://www.ibm.com/developerworks/cn/linux/l-cn-pexpect1/ ConfigParser模块:http://blog.china ...
- 【QT】QString类型转换为const char*(toLatin1)
Qstring str = "helloworld"; char *s; QByteArray ba = str.toLatin1(); s = ba.data(); toLati ...
- java反序列化Commons-Collections5分析
BadAttributeValueException package org.lain.poc; import org.apache.commons.collections.Transformer; ...