Beispiel #1
0
        /// <summary>
        /// 添加菜单
        /// </summary>
        public void AddMenu()
        {
            EHECD_FunctionMenuDTO menu /*要添加的菜单*/ = JSONHelper.GetModel <EHECD_FunctionMenuDTO>(RequestParameters.data.ToString());

            //菜单业务对象
            IMenuManager menubll = DI.DIEntity.GetInstance().GetImpl <IMenuManager>();

            CreateSyslogInfo();
            //添加菜单
            var ret = menubll.AddMenu(menu /*要添加的菜单*/, RequestParameters.dynamicData);

            if (ret != null)
            {
                //返回给页面添加好的菜单对象(tree使用的节点)
                result.Data = new
                {
                    id         = ret.ID,
                    text       = ret.sMenuName,
                    state      = "closed",
                    @checked   = false,
                    attributes = new { type = "menu", url = ret.sUrl, order = ret.iOrder },
                    children   = new object[0]
                };

                //从session获取用户的权限和菜单等信息
                var userRoleMenu = GetSessionInfo(SessionInfo.USER_MENUS /*用户的权限和菜单等信息*/) as UserRoleMenuInfo;

                if (userRoleMenu != null)
                {
                    //更新添加的菜单到session缓存
                    userRoleMenu.AllMenu.Add(new UserMenu
                    {
                        Buttons   = new List <UserMenuButton>(),
                        ChildMenu = new List <UserMenu>(),
                        ID        = ret.ID,
                        iOrder    = ret.iOrder,
                        sMenuName = ret.sMenuName,
                        sPID      = ret.sPID,
                        sUrl      = ret.sUrl
                    });
                }
                else
                {
                    result.Succeeded = false;
                    result.Msg       = "会话菜单缓存获取失败";
                    return;
                }

                //重新获取菜单结构
                userRoleMenu.UserMenu = InitMenu(userRoleMenu.AllMenu);
                SetSessionInfo(SessionInfo.USER_MENUS /*用户的权限和菜单等信息*/, userRoleMenu);
                result.Succeeded = true;
            }
            else
            {
                result.Succeeded = false;
                result.Msg       = "添加菜单失败,请联系管理员";
            }
        }