using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages; /// <summary>
/// 安全字段
/// </summary>
public class FieldSecurityProfileHelper
{
public static readonly string entityName = "fieldsecurityprofile";
public static readonly string FieldPermission = "FieldPermission";
public Guid fieldSecurityProfileId = Guid.Empty;
public Guid fieldPermissionId = Guid.Empty; /// <summary>
/// 创建安全字段
/// </summary>
public void Create(IOrganizationService service)
{
Entity en = new Entity() { LogicalName = entityName };
en["name"] = "new_name";
fieldSecurityProfileId = service.Create(en);
} /// <summary>
/// 给安全字段添加团队
/// </summary>
/// <param name="service">服务</param>
/// <param name="teamId">团队</param>
public void AddTeam(IOrganizationService service, Guid teamId)
{
AssociateRequest request = new AssociateRequest();
request.Relationship = new Relationship("teamprofiles_association");
request.Target = new EntityReference() { LogicalName = entityName, Id = fieldSecurityProfileId };
request.RelatedEntities = new EntityReferenceCollection();
request.RelatedEntities.Add(new EntityReference() { LogicalName = "team", Id = teamId });
service.Execute(request);
} /// <summary>
/// 给安全字段移除团队
/// </summary>
/// <param name="service">服务</param>
/// <param name="teamId">团队</param>
public void RemoveTeam(IOrganizationService service, Guid teamId)
{
DisassociateRequest request = new DisassociateRequest();
request.Relationship = new Relationship("teamprofiles_association");
request.Target = new EntityReference() { LogicalName = entityName, Id = fieldSecurityProfileId };
request.RelatedEntities = new EntityReferenceCollection();
request.RelatedEntities.Add(new EntityReference() { LogicalName = "team", Id = teamId });
service.Execute(request);
} /// <summary>
/// 给安全字段添加用户
/// </summary>
/// <param name="service">服务</param>
/// <param name="teamId">用户</param>
public void AddUser(IOrganizationService service, Guid userId)
{
AssociateRequest request = new AssociateRequest();
request.Relationship = new Relationship("systemuserprofiles_association");
request.Target = new EntityReference() { LogicalName = entityName, Id = fieldSecurityProfileId };
request.RelatedEntities = new EntityReferenceCollection();
request.RelatedEntities.Add(new EntityReference() { LogicalName = "systemuser", Id = userId });
service.Execute(request);
} /// <summary>
/// 给安全字段移除用户
/// </summary>
/// <param name="service">服务</param>
/// <param name="teamId">用户</param>
public void RemoveUser(IOrganizationService service, Guid userId)
{
DisassociateRequest request = new DisassociateRequest();
request.Relationship = new Relationship("systemuserprofiles_association");
request.Target = new EntityReference() { LogicalName = entityName, Id = fieldSecurityProfileId };
request.RelatedEntities = new EntityReferenceCollection();
request.RelatedEntities.Add(new EntityReference() { LogicalName = "systemuser", Id = userId });
service.Execute(request);
} /// <summary>
/// 把安全字段和实体关联
/// </summary>
/// <param name="service">服务</param>
/// <param name="entity">实体</param>
public void CreateAttribute(IOrganizationService service, string entity)
{
Entity en = new Entity() { LogicalName = FieldPermission };
//实体名称
en["entityname"] = entity;
en["canread"] = new OptionSetValue(FieldPermissionType.Allowed);
en["attributelogicalname"] = "new_attributename";
en["fieldsecurityprofileid"] = new EntityReference() { LogicalName = entityName, Id = fieldSecurityProfileId };
fieldSecurityProfileId = service.Create(en);
} /// <summary>
/// 删除实体里面的安全字段
/// </summary>
/// <param name="service">服务</param>
public void RemoveAttribute(IOrganizationService service)
{
service.Delete(FieldPermission, fieldSecurityProfileId);
} /// <summary> ///
/// 删除安全字段 ///
/// </summary>
public void Delete(IOrganizationService service) { service.Delete(entityName, fieldSecurityProfileId); }
}

Field Security Profile Helper的更多相关文章

  1. Wind River Linux 6 Security Profile

    2692407267@qq.com,很多其它内容请关注http://user.qzone.qq.com/2692407267 Wind River Linux 6 Security Profile

  2. Dynamices CRM Permission Issue (Security role UI to privilege mapping)'s solution

    select * from privilege where  privilegeid = 'a4736385-9763-4a64-a44b-cd5933edc631' Security role UI ...

  3. Dynamics CRM 2011-RootComponent Type

    笔者因为时不时要导出solution,对solution xml进行处理,所以把xml中的rootcomponent type列一下  Type Description 1 Entity 2 Attr ...

  4. Understanding and Using HRMS Security in Oracle HRMS

    Understanding and Using HRMS Security in Oracle HRMS Product:Oracle Human Resources Minimum Version: ...

  5. Implementing SQL Server Row and Cell Level Security

    Problem I have SQL Server databases with top secret, secret and unclassified data.  How can we estab ...

  6. 应付配置文件 Profile

    (N) System Administrator > Profile > System Profile Option Name Site Application Responsibilit ...

  7. Security Software Engineer

    Security Software Engineer Are you excited to be part of the VR revolution and work on cutting edge ...

  8. IMS Global Learning Tools Interoperability™ Implementation Guide

    Final Version 1.1 Date Issued:            13 March 2012 Latest version:         http://www.imsglobal ...

  9. P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

    P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May ...

随机推荐

  1. 从零开始——JSON ARRAY&JSON OBJECT

    在学习“基于角色的权限”的例子中,遇到了json object和json array,因此在一番学习之后对此要点进行粗略整理. 参考: https://my.oschina.net/u/2601842 ...

  2. 创建 In-app Billing 商品

    创建可供购买的 In-app Billing 商品 在你发布 In-app Billing 应用前,你需要在 Google Play 开发者控制台 定义可供购买的数字商品列表. 在 Google Pl ...

  3. git使用教程2-更新github上代码

    前面一篇已经实现首次上传代码到github了,迈出了装逼第一步,本篇继续讲如何把本地更新的代码同步更新到github上 一.clone代码 1.把大神的代码clone到本地,或者clone自己gith ...

  4. Python学习---Django路由系统【all】

    Django URL (路由系统) Django URL (路由系统): URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL模式以及要为该URL模式调用的视图函数之间的映 ...

  5. 每年支付 m 次的年金

    每年支付 m 次的年金 n 表示年数.m 表示每年的付款次数.i 表示年实际利率. 一.期末付年金(annuity-immediate payable mthly): 每年支付m次, 每次的付款为1/ ...

  6. 配置 Tomcat 服务 和 自启动

    如果我们使用war 包进行部署项目的时候,需要把包放进Tomcat的目录下,为了使我们的服务能够在服务器重启的时候自动启动起来,我们需要把Tomcat设置成自起服务. 配置 Tomcat 服务 新建服 ...

  7. cheerio数据抓取

    很多语言都能写个爬虫抓取数据,js自然也可以,使用cheerio可以支持css检索,较快捷的获取需要的数据.首先,先把node.js给安装了.可到官网下载.安装好node.js后,使用npm安装che ...

  8. python的os和sys模块

    OS模块: 提供对操作系统进行调用的接口 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目 ...

  9. Angular2 *ngFor把数据显示在多个input中出错解决方法

    点击添加按钮会自动添加一个空的input组 html <div class="form-inline"> <label class="form-cont ...

  10. vim基础初步

    vim文本编辑器初步 一.跟vi编辑器的关系 可以说vim编辑器是vi编辑器的升级版,它保留了vi编辑器的所有东西,而且加入了自己的新的特性. 比如说:支持跨平台,支持语法高亮,支持多级撤销等. ++ ...