Ejemplo n.º 1
0
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public List <Menu> GetMenuListBy(long pid)
        {
            //获取所有菜单
            var menuList = MenuBll.GetMenus();
            var datas    = menuList.Where(m => m.Pid == pid).OrderBy(m => m.Seq).ToList();

            if (datas == null || !datas.Any())
            {
                return(new List <Menu>());
            }
            return(datas);
        }
Ejemplo n.º 2
0
 public JsonResult GetLeftMenu(long topMenuId)
 {
     if (UserContext.CurrentUser.GId == 1)
     {
         //如果是平台管理员
         //获取父级菜单
         var parentMenuList = GetMenuListBy(0);
         var kidMenuList    = new List <Menu>();
         if (parentMenuList != null && parentMenuList.Any())
         {
             if (topMenuId <= 0)
             {
                 //获取第一个菜单的子级
                 var first = parentMenuList[0];
                 kidMenuList = GetMenuListBy(first.Id);
                 if (kidMenuList == null)
                 {
                     kidMenuList = new List <Menu>();
                 }
             }
             else
             {
                 var first = parentMenuList.FirstOrDefault(m => m.Id == topMenuId);
                 if (first != null)
                 {
                     kidMenuList = GetMenuListBy(first.Id);
                     if (kidMenuList == null)
                     {
                         kidMenuList = new List <Menu>();
                     }
                 }
             }
         }
         kidMenuList = kidMenuList.Where(a => a.IsStop == false).ToList();
         kidMenuList = kidMenuList.OrderBy(a => a.Seq).ToList();
         return(Json(kidMenuList, JsonRequestBehavior.AllowGet));
     }
     else
     {
         List <Menu> leftMenuList = new List <Menu>();//页面左侧菜单
         //获取用户权限
         var groupAuthList = GroupAuthorityBll.GetGroupAuthorityList(UserContext.CurrentUser.GId);
         if (groupAuthList == null || !groupAuthList.Any())
         {
             return(Json(leftMenuList, JsonRequestBehavior.AllowGet));
         }
         //获取菜单
         var parent = MenuBll.GetById(topMenuId);
         //获取所有菜单
         var menuList = MenuBll.GetMenus();
         //获取所有的子菜单
         var kidList = menuList.Where(m => m.Pid == parent.Id);
         if (kidList != null && kidList.Any())
         {
             foreach (var auth in groupAuthList)
             {
                 var menu = kidList.FirstOrDefault(m => m.Id == auth.MenuId);
                 if (menu != null && !leftMenuList.Exists(m => m.Id == menu.Id))
                 {
                     leftMenuList.Add(menu);
                 }
             }
         }
         leftMenuList = leftMenuList.Where(a => a.IsStop == false).ToList();
         leftMenuList = leftMenuList.OrderBy(a => a.Seq).ToList();
         return(Json(leftMenuList, JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 3
0
        public JsonResult SaveAuth(long groupId, GroupAuthModel[] models)
        {
            var apiResult = new APIResult();

            if (groupId == 1)
            {
                apiResult.Ret = -1;
                apiResult.Msg = "不可设置平台管理员权限";
                return(Json(apiResult));
            }
            List <GroupAuthority> authList = new List <GroupAuthority>();

            if (models.Length == 0)
            {
                apiResult.Ret = -1;
                apiResult.Msg = "请选择权限";
                return(Json(apiResult));
            }
            //获取所有菜单
            var menuList = MenuBll.GetMenus();
            //获取所有按钮
            var btnList = FuncBtnBll.GetList();

            try
            {
                foreach (var item in models)
                {
                    long menuId = item.id;
                    var  menu   = menuList.FirstOrDefault(m => m.Id == menuId);
                    if (menu == null)
                    {
                        continue;
                    }
                    string btnsStr = item.btnIdStr;
                    if (string.IsNullOrWhiteSpace(btnsStr))
                    {
                        continue;
                    }
                    string[] btnIdArray = btnsStr.Split(',');
                    if (btnIdArray.Length == 0)
                    {
                        continue;
                    }
                    foreach (var btnIdString in btnIdArray)
                    {
                        long btnId = 0;
                        if (long.TryParse(btnIdString, out btnId))
                        {
                            var funcBtn = btnList.FirstOrDefault(m => m.Id == btnId);
                            authList.Add(new GroupAuthority()
                            {
                                GroupId        = groupId,
                                MenuId         = menuId,
                                MenuController = menu.MenuController,
                                FuncBtnId      = funcBtn.Id,
                                FuncBtnName    = funcBtn.Name,
                                FuncBtnCode    = funcBtn.Code,
                                Seq            = funcBtn.Seq,
                                CDate          = TypeConvert.DateTimeToInt(DateTime.Now)
                            });
                        }
                    }
                }

                if (authList.Count == 0)
                {
                    GroupAuthorityBll.Delete(groupId);
                }
                else
                {
                    GroupAuthorityBll.Delete(groupId);
                    authList.ForEach(m => {
                        GroupAuthorityBll.AddOrUpdate(m);
                    });
                }
            }
            catch (Exception ex)
            {
                apiResult.Ret = -1;
                apiResult.Msg = ex.Message;
                if (!(ex is OperationExceptionFacade))
                {
                    LogFactory.GetLogger().Log(LogLevel.Error, ex);
                }
            }
            return(Json(apiResult));
        }