Ejemplo n.º 1
0
        /// <summary>
        /// 根据用户获取功能菜单
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <returns></returns>
        public List <Menu> GetMenuByUser(string userId)
        {
            List <Menu> result    = new List <Menu>();
            List <Menu> allMenuls = new List <Menu>();
            List <Menu> subMenuls = new List <Menu>();

            string where = string.Format("Layers=1");
            IEnumerable <Menu> allMenus = _MenuRepository.GetAllByIsNotDeleteAndEnabledMark();

            allMenuls = allMenus.ToList();
            if (userId == string.Empty) //超级管理员
            {
                return(allMenuls);
            }
            var user = userRepository.Get(userId);

            if (user == null)
            {
                return(result);
            }
            var userRoles = user.RoleId;

            where = string.Format("ItemType = 1 and ObjectType = 1 and ObjectId='{0}'", userRoles);
            var Menus = roleAuthorizeRepository.GetListWhere(where);

            foreach (RoleAuthorize item in Menus)
            {
                Menu MenuEntity = allMenuls.Find(t => t.Id == item.ItemId);
                if (MenuEntity != null)
                {
                    result.Add(MenuEntity);
                }
            }
            return(result.OrderBy(t => t.SortCode).ToList());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据角色和项目类型查询权限
        /// </summary>
        /// <param name="roleIds">角色Id</param>
        /// <param name="itemType"></param>
        /// <returns></returns>
        public IEnumerable <RoleAuthorize> GetListRoleAuthorizeByRoleId(string roleIds, string itemType)
        {
            IEnumerable <RoleAuthorize> list = _repository.GetListWhere(string.Format("ItemType in({0}) and ObjectId in ({1}) and ObjectType=1", itemType, roleIds));

            return(list);
        }