Exemplo n.º 1
0
        public List <Int32> UseDataPermissionFilter()
        {
            var pm = PermissionManager.Current;

            if (pm != null && pm.DataPermissions != null && pm.DataPermissions.Count > 0)
            {
                List <Int32> dataPermissionIDs = new List <Int32>();
                //遍历组装数据权限ID集合
                pm.DataPermissions.ForEach(e => dataPermissionIDs.Add(e.ID));
                //根据数据权限ID集合获取角色与数据权限映射
                var rdps = RoleDataPermission.FindAllByDataPermissionIDs(dataPermissionIDs);
                if (rdps != null && rdps.Count > 0)
                {
                    List <Int32> roleIDs = new List <Int32>();
                    //遍历组装角色ID集合
                    rdps.ForEach(e =>
                    {
                        if (!roleIDs.Contains(e.RoleID))
                        {
                            roleIDs.Add(e.RoleID);
                        }
                    });
                    //根据角色ID集合查找用户与角色映射
                    var adminRoles = AdminRole.FindAllByRoleIDs(roleIDs);
                    if (adminRoles != null && adminRoles.Count > 0)
                    {
                        List <Int32> adminIDs = new List <Int32>();
                        adminRoles.ForEach(e => adminIDs.Add(e.AdminID));
                        return(adminIDs);
                    }
                }
            }
            return(null);
        }