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. C# 元素组合算法

    class Program { static void Main(string[] args) { string[] a = { "A", "B", " ...

  2. Mycat中间件

    数据库中间件Mycat自我介绍 一.mycat概述 1.功能介绍 mycat一个开源的分布式数据库系统,是一个实现了mysql协议的server前端用户可以把它看成一个数据库代理,用mysql客户端工 ...

  3. 10 套华丽的 CSS3 按钮推荐

    在过去的Web开发中,通常使用Photoshop来设计按钮的样式.不过随着CSS3技术的发展,你完全可以通过几行代码来定制一个漂亮的按钮,并且还可以呈现渐变.框阴影.文字阴影等效果.此类按钮最大的优势 ...

  4. 基于双下划线的跨表查询 (join查询)

    因为你的数据库中的查询就是重点  那么你的django提供的orm也是查询语句最重点 ,也提供的查询方法比较的多,下面我们学习下类似于MYSQL的连表(join)查询 Django 还提供了一种直观而 ...

  5. Win10 mysql容器启动命令

    docker run --name mysql -it -p : -e MYSQL_ROOT_PASSWORD=Hongfund5013 -e MYSQL_USER=hongfund_os -e MY ...

  6. Python学习---Django误删除sql表后,如何创建数据

    误删除sql表后,怎么创建数据? 仅仅适合单表,多表因为涉及约束, python mangage.py makemigrations  --> 生成migrations目录和根数据库对应的sql ...

  7. OSG3.0.1的编译

    在OSG-中国有很多关于OSG的资料,包括OSG的编译和教程. 要编译OSG首先需要准备的包: 1,OSG3.0.1源代码: 2,CMAKE: 3,OSG用到的第三方库: 4,OSG Data:OSG ...

  8. December 26th 2016 Week 53rd Monday

    Better to light one candle than to curse the darkness. 与其诅咒黑暗,不如燃起蜡烛. If the world is so cruel, I wo ...

  9. 在ASP.NET MVC中,使用Bundle来打包压缩js和css(转)

    转自:http://www.cnblogs.com/xwgli/p/3296809.html 在ASP.NET MVC4中(在WebForm中应该也有),有一个叫做Bundle的东西,它用来将js和c ...

  10. Linq to Entities,ADO.NET Entity Framework 模型优先

    一.概念: Database First(数据库优先):存在的DB------------->生成Data Model  .edmx文件 Model First(模型优先):Data Model ...