码迷,mamicode.com
首页 > 其他好文 > 详细

crm操作权限

时间:2014-07-18 11:12:17      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:crm操作权限   crm查询实体的权限   crm查询一个用户具有的权限   crm检索系统中定义的特权集   

    using System;
    using Microsoft.Xrm.Sdk;
    using Microsoft.Xrm.Sdk.Query;
    using System.Collections.Generic;
    using Microsoft.Crm.Sdk.Messages;

    /// <summary>
    /// 权限
    /// </summary>
    public class PrivilegeHelper
    {
        public static readonly string entityName = "privilege";

        /// <summary>
        /// 查询一个实体的权限
        /// 一般的实体都有8个基本的权限
        /// </summary>
        public List<Privilege> SearchPrivilegeByEntityName(IOrganizationService service, string name)
        {
            List<Privilege> list = new List<Privilege>();
            //一般的实体都有8个权限,这里假设实体是:account
            //prvCreateAccount: 创建客户,prvReadAccount: 读取客户记录,prvWriteAccount: 修改客户
            //prvDeleteAccount: 删除客户,prvAppendAccount: 追加,prvAppendToAccount: 追加到
            //prvAssignAccount: 分配客户,prvShareAccount: 共享客户
            QueryExpression query = new QueryExpression();
            query.EntityName = entityName;
            query.ColumnSet = new ColumnSet("name");
            query.Criteria.AddCondition(new ConditionExpression("name",ConditionOperator.Like,"prv%" + name));
            EntityCollection ec = service.RetrieveMultiple(query);
            if (ec != null && ec.Entities.Count > 0)
            {
                foreach(Entity en in ec.Entities)
                {
                    Privilege p = new Privilege();
                    p.id = en.Id;
                    p.name = en["name"].ToString();
                    list.Add(p);
                }
            }
            return list;
        }

        /// <summary>
        /// 通过id查询一个权限
        /// </summary>
        /// <param name="service">服务</param>
        /// <param name="privilegeId">权限id</param>
        public Privilege SearchPrivilegeById(IOrganizationService service,Guid privilegeId)
        {
            Entity en = service.Retrieve(entityName, privilegeId, new ColumnSet("name"));
            Privilege p = new Privilege() { id = privilegeId };
            p.name = en["name"].ToString();
            return p;
        }

        /// <summary>
        /// 查询一个用户具有的权限
        /// </summary>
        /// <param name="service">服务</param>
        /// <param name="userId">用户</param>
        public void SearchPrivilegeByUserId(IOrganizationService service,Guid userId)
        {
            RetrieveUserPrivilegesRequest request = new RetrieveUserPrivilegesRequest();
            request.UserId = userId;

            RetrieveUserPrivilegesResponse response = (RetrieveUserPrivilegesResponse)service.Execute(request);
            if (response.RolePrivileges != null)
            {
                RolePrivilege[] arrayResult = response.RolePrivileges;
            }
        }

        /// <summary>
        /// 检索系统中定义的特权集
        /// </summary>
        /// <param name="service">服务</param>
        public List<Privilege> SearchAllPrivilege(IOrganizationService service)
        {
            List<Privilege> list = new List<Privilege>();
            RetrievePrivilegeSetRequest request = new RetrievePrivilegeSetRequest();
            RetrievePrivilegeSetResponse response = (RetrievePrivilegeSetResponse)service.Execute(request);
            if (response.EntityCollection != null)
            {
                EntityCollection ec = response.EntityCollection;
                if (ec != null && ec.Entities.Count > 0)
                {
                    foreach (Entity en in ec.Entities)
                    {
                        Privilege p = new Privilege();
                        p.id = en.Id;
                        p.name = en["name"].ToString();
                        list.Add(p);
                    }
                }
            }
            return list;
        }

        public class Privilege
        {
            public Guid id { get; set; }
            public string name { get; set; }
        }
    }

crm操作权限,布布扣,bubuko.com

crm操作权限

标签:crm操作权限   crm查询实体的权限   crm查询一个用户具有的权限   crm检索系统中定义的特权集   

原文地址:http://blog.csdn.net/y_f123/article/details/37921645

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!