Пример #1
0
        private LoginUserModel GetUserPermission(AdminUserInfo userInfo)
        {
            var loginUserModel = new LoginUserModel();

            loginUserModel.AdminUserInfo = userInfo;
            if (userInfo.Status == 1)
            {
                var lstMenuRoot = new List <AdminMenuModel>();
                IList <AdminMenuInfo> lstMenu;
                //获取菜单
                if (userInfo.IsAdmin)
                {
                    lstMenu = adminUserDAL.GetAllMenuPermission();
                }
                else
                {
                    lstMenu = adminUserDAL.GetMenuListByUserID(userInfo.id);
                }
                if (lstMenu != null && lstMenu.Count > 0)
                {
                    //添加主菜单
                    lstMenuRoot.AddRange(lstMenu.Where(root => root.ParentPermission == EnumPermission.None).Select(p => new AdminMenuModel
                    {
                        root = p,
                        //添加子菜单
                        children = lstMenu.Where(child => child.IsShow && child.ParentPermission == p.Permission).ToList()
                    }));
                }
                var lstPermission = lstMenu.Select(p => p.Permission).ToList();
                loginUserModel.MenuList      = lstMenuRoot;
                loginUserModel.PermissionSet = new HashSet <EnumPermission>(lstPermission);
            }
            return(loginUserModel);
        }