Exemplo n.º 1
0
        /// <summary>
        /// 根据登陆id菜单id判断是否有权限
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static bool ReturnMenuByUserIdMenuId(string userId, string menuId, string projectId)
        {
            bool returnValue = false;
            var  menu        = SysMenuService.GetSysMenuByMenuId(menuId);

            if (menu != null)
            {
                ///1、当前用户是管理员
                ///2、当前菜单是个人设置 资源库|| menu.MenuType == BLL.Const.Menu_Resource
                if (userId == Const.sysglyId || userId == Const.hfnbdId || userId == Const.sedinId || menu.MenuType == Const.Menu_Personal)
                {
                    returnValue = true;
                }
                else if (string.IsNullOrEmpty(projectId))               ///本部、系统设置
                {
                    var user = BLL.UserService.GetUserByUserId(userId); ////用户
                    if (user != null && !string.IsNullOrEmpty(user.RoleId))
                    {
                        var power = Funs.DB.Sys_RolePower.FirstOrDefault(x => x.MenuId == menuId && x.RoleId == user.RoleId);
                        if (power != null)
                        {
                            returnValue = true;
                        }

                        // var getRoles=Funs.DB.Sys_Role.FirstOrDefault(x=> user.RoleId)
                    }
                }
                else
                {
                    ///3、管理角色、领导角色能访问项目菜单
                    bool isLeaderManage = IsLeaderOrManage(userId);
                    if (isLeaderManage && menu.MenuType == BLL.Const.Menu_Project)
                    {
                        returnValue = true;
                    }
                    else
                    {
                        var puser = ProjectUserService.GetProjectUserByUserIdProjectId(projectId, userId); ////用户
                        if (puser != null && !string.IsNullOrEmpty(puser.RoleId))
                        {
                            List <string> roleIdList = Funs.GetStrListByStr(puser.RoleId, ',');
                            var           power      = Funs.DB.Sys_RolePower.FirstOrDefault(x => x.MenuId == menuId && roleIdList.Contains(x.RoleId));
                            if (power != null)
                            {
                                returnValue = true;
                            }
                        }
                    }
                }
            }
            return(returnValue);
        }
Exemplo n.º 2
0
        /// <summary>
        ///  获取当前人菜单集合
        /// </summary>
        /// <param name="projectId">项目ID</param>
        /// <param name="userId">用户id</param>
        /// <returns>是否具有权限</returns>
        public static List <string> GetAllMenuList(string projectId, string userId)
        {
            Model.SUBHSSEDB       db    = Funs.DB;
            List <Model.Sys_Menu> menus = new List <Model.Sys_Menu>();
            /// 启用且末级菜单
            var getMenus = from x in db.Sys_Menu
                           where x.IsUsed == true && x.IsEnd == true select x;

            if (!string.IsNullOrEmpty(projectId))
            {
                getMenus = getMenus.Where(x => x.MenuType == Const.Menu_Project);
            }

            if (userId == Const.sysglyId || userId == Const.hfnbdId || userId == Const.sedinId)
            {
                menus = getMenus.ToList();
            }
            else
            {
                if (string.IsNullOrEmpty(projectId))
                {
                    var user = UserService.GetUserByUserId(userId); ////用户
                    if (user != null)
                    {
                        menus = (from x in getMenus
                                 join y in db.Sys_RolePower on x.MenuId equals y.MenuId
                                 where y.RoleId == user.RoleId
                                 select x).ToList();
                    }
                }
                else
                {
                    var pUser = ProjectUserService.GetProjectUserByUserIdProjectId(projectId, userId); ///项目用户
                    if (pUser != null)
                    {
                        List <string> roleIdList = Funs.GetStrListByStr(pUser.RoleId, ',');
                        menus = (from x in db.Sys_RolePower
                                 join y in getMenus on x.MenuId equals y.MenuId
                                 where roleIdList.Contains(x.RoleId)
                                 select y).ToList();
                    }
                }
            }

            return(menus.Select(x => x.MenuId).ToList());
        }