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操作权限的更多相关文章

  1. Dynamics CRM 2011 权限管理(转)

    http://www.cnblogs.com/LeoTang/p/3344265.html Dynamics CRM 2011 权限管理 CRM系统基于角色的权限主要通过部门.角色.用户.团队来 进行 ...

  2. Dynamics CRM 2011 权限管理

    CRM系统基于角色的权限主要通过部门.角色.用户.团队来进行控制.每一个实体记录的所有者(Owner)必然是某一个用户或团队.一个用户或团队必然归属于一个且只归属于一个部门,但团队的成员即用户可以来自 ...

  3. Django项目:CRM(客户关系管理系统)--85--75PerfectCRM实现CRM扩展权限

    # sales_urls.py # ————————47PerfectCRM实现CRM客户报名流程———————— from django.conf.urls import url from bpm. ...

  4. 用最基本的EF+MVC+JQ+AJAX+bootstrap实现权限管理的简单实例 之登陆和操作权限

    先来一堆关于上篇文章的废话(不喜者点此隐藏) 今天把博客加了个小功能,就是点标题可以隐藏或展示相关内容,做法很傻,就是引用了bootstrap的两个css类和全部的js文件,其实这样的小功能完全应该自 ...

  5. 053医疗项目-模块五:权限设置-将用户操作权限写入Session

    权限管理指的是用户授权,与拦截器没有关系.拦截器只是一个技术,也可以用别的技术来实现的.别人问你权限管理,可不要和人家说什么拦截器.要说用户授权 前一篇文章是把实现了不同的用户呈现不用的菜单.这一篇文 ...

  6. RDIFramework.NET ━ 9.7 操作权限项管理 ━ Web部分

    RDIFramework.NET ━ .NET快速信息化系统开发框架 9.7 操作权限项管理 -Web部分 随着经济全球化趋势的发展和企业间竞争的加剧,企业对管理要求不断变化.提高,越来越多的信息都表 ...

  7. 【转】操作权限不够?教你开启Win7管理员帐户

    在Win7中进行一些设置,或修改某些文件时,经常会弹出当前帐户没有操作权限的提示,即使已经是管理员账户也不行.事实上,出于安全方面的考虑,默认情况下Win7系统的系统管理员Administrator账 ...

  8. Tornado 判断用户登录状态和操作权限(装饰器)

    判断是否登录: def authenticated(method): '''''' @functools.wraps(method) def wrapper(self, *args, **kwargs ...

  9. 打通MySQL的操作权限

    打通MySQL的操作权限 前面已经总结了<XAMPP的配置与使用>,虽然可以直接通过GUI控制面板去启动MySQL服务,但是有些相关的操作则需要在Windows中的CMD命令窗口中去对My ...

随机推荐

  1. Codeforces Round #237 (Div. 2)

    链接 A. Valera and X time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inp ...

  2. 156. Binary Tree Upside Down

    题目: Given a binary tree where all the right nodes are either leaf nodes with a sibling (a left node ...

  3. org.springframework.jdbc.datasource

    org.springframework.jdbc.datasource.DataSourceUtils /** * Actually obtain a JDBC Connection from the ...

  4. leetcode面试准备:Add and Search Word - Data structure design

    leetcode面试准备:Add and Search Word - Data structure design 1 题目 Design a data structure that supports ...

  5. tlplayer for android V2.7(支持变速不变调) 2014-07-20更新

    2014-07-20新版本已经修复部分视频倾斜问题,已经更新到服务器,需要的朋友自行下载. 此版本修正了倾斜问题,增加水印等功能.可以动态添加水印. tlplayer for android V2.6 ...

  6. 关于数组和List之间相互转换的方法

    1.List转换成为数组:返回数组的运行时类型.如果列表能放入指定的数组.否则,将根据指定数组.如果指定的数组的元素比列表的多),那么会将存储列表元素的数组. 返回:包含列表元素的list.add(& ...

  7. 小图用 imageNamed: 大图用 dataWithContentsOfFile:options

    1down voteaccepted If you're loading images like:[UIImage imageNamed:@"myImage.png"];Then ...

  8. XCode中Architecturs配置及常见问题

    http://lanvige.github.io/2014/03/19/architecturs-in-xcode/ XCode 5.1升级后因arm64和CocoaPods的原因,痛了一天,终于解决 ...

  9. JavaScript里的类和继承

    JavaScript与大部分客户端语言有几点明显的不同: JS是 动态解释性语言,没有编译过程,它在程序运行过程中被逐行解释执行JS是 弱类型语言,它的变量没有严格类型限制JS是面向对象语言,但 没有 ...

  10. CSS clip:rect矩形剪裁功能及一些应用介绍

    CSS clip:rect矩形剪裁功能及一些应用介绍 by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.co ...