博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Field Security Profile Helper
阅读量:5370 次
发布时间:2019-06-15

本文共 3863 字,大约阅读时间需要 12 分钟。

using System;using Microsoft.Xrm.Sdk;using Microsoft.Xrm.Sdk.Messages;/// /// 安全字段/// 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;    ///     /// 创建安全字段    ///      public void Create(IOrganizationService service)    {        Entity en = new Entity() { LogicalName = entityName };        en["name"] = "new_name";        fieldSecurityProfileId = service.Create(en);    }    ///     /// 给安全字段添加团队    ///     /// 服务    /// 团队    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);    }    ///     /// 给安全字段移除团队    ///     /// 服务    /// 团队    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);    }    ///     /// 给安全字段添加用户    ///     /// 服务    /// 用户    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);    }    ///     /// 给安全字段移除用户    ///     /// 服务    /// 用户    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);    }    ///     /// 把安全字段和实体关联    ///     /// 服务    /// 实体    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);    }    ///     /// 删除实体里面的安全字段    ///     /// 服务    public void RemoveAttribute(IOrganizationService service)    {        service.Delete(FieldPermission, fieldSecurityProfileId);    }    ///          ///     /// 删除安全字段         ///     ///              public void Delete(IOrganizationService service) { service.Delete(entityName, fieldSecurityProfileId); }}

 

转载于:https://www.cnblogs.com/bennylam/p/9921425.html

你可能感兴趣的文章
20189215 2018-2019-2 《密码与安全新技术专题》第13周作业
查看>>
第四周作业
查看>>
一、HTML基础
查看>>
蓝牙进阶之路 (002) - HC-05与HC-06的AT指令的区别(转)
查看>>
mysql的limit经典用法及优化
查看>>
C#后台程序与HTML页面中JS方法互调
查看>>
mysql 同一个表中 字段a 的值赋值到字段b
查看>>
antiSMASH数据库:微生物次生代谢物合成基因组簇查询和预测
查看>>
UNICODE与ANSI的区别
查看>>
nginx 配置实例
查看>>
Flutter - 创建底部导航栏
查看>>
ASP.NET MVC 教程-MVC简介
查看>>
SQL Server索引 - 聚集索引、非聚集索引、非聚集唯一索引 <第八篇>
查看>>
转载:详解SAP TPM解决方案在快速消费品行业中的应用
查看>>
Android OpenGL ES 开发(N): OpenGL ES 2.0 机型兼容问题整理
查看>>
项目中用到的技术及工具汇总(持续更新)
查看>>
【算法】各种排序算法测试代码
查看>>
HDU 5776 Sum
查看>>
201521123044 《Java程序设计》第9周学习总结
查看>>
winfrom 图片等比例压缩
查看>>