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. java "Too small initial heap" 错误

    Tomcat内存配置 JAVA_OPTS="-server -Duser.timezone=GMT+08-Xms1024m -Xmx1024m -XX:PermSize=1024m -Xmn ...

  2. Json转Map

    http = new HttpClient**();//此处封装一下发请求的类 Map<String, String> map = new HashMap<String, Strin ...

  3. 如何理解springaop

    初看aop,上来就是一大堆术语,而且还有个拉风的名字,面向切面编程,都说是oop的一种有益补充等等,一下子让你不知所措,心想着:怪不得很多人都和我说aop多难多难.当我看进去以后,我才发现:它就是一些 ...

  4. Apache配置支持目录浏览

      主配置文件 httpd.conf 中修改: 1)添加支持模块 LoadModule autoindex_module modules/mod_autoindex.so LoadModule dir ...

  5. 微软最新设计Fluent Design System初体验

    微软最新设计Fluent Design System初体验 本文图片不全!建议移步知乎专栏查看!!! https://zhuanlan.zhihu.com/p/30582886 原创 2017-11- ...

  6. http状态码汇总及问题经验总结

    我们经常会遇到404.500.302等提示,它们究竟是什么意思呢?除了这几个常见的状态码外,还有哪些我们没有遇到过的但有可能出现的状态码呢?这里本人做了一个汇总,与大家分享一下. 常见的HTTP错误可 ...

  7. SQL Server系统常用存储过程

    SQL Server系统存储过程也是好几百个,算了,还是写几个常用的. 1.sp_help 查询表的信息 执行存储过程: sp_help Person 显示结果如下: 妈了个B,有了这张图,你还不懂怎 ...

  8. 使用JAVA进行排序

    利用JAVA完成排序 当我们在进行数据库进行查询的时候,当需要按某个字段来进行排序的时候,可以使用SQL语句来完成排序,可以升序,也可以降序.JAVA中的Collections类也可以完成这种操作,S ...

  9. jq复制到剪切板插件clipboard.min.js(兼容IE9)

    /*! * clipboard.js v1.5.5 * https://zenorocha.github.io/clipboard.js * * Licensed MIT 漏 Zeno Rocha * ...

  10. Guava包学习-Multimap

    它和上一章的MultiSet的继承结果很相似,只不过在上层的接口是Multimap不是Multiset. Multimap的特点其实就是可以包含有几个重复Key的value,你可以put进入多个不同v ...