public ActionResult TopMenu()
        {
            var            model          = new Menu();
            User           user           = _workContext.User;
            PermissionMenu permissionMenu = user.Menu;

            foreach (var item in permissionMenu.Items)
            {
                MenuItem menuItem = new MenuItem
                {
                    Name           = item.Name,
                    NavigateUrl    = item.NavigateUrl,
                    PermissionCode = item.PermissionCode
                };

                foreach (var subItem in item.SubItems)
                {
                    menuItem.SubItems.Add(new MenuItem
                    {
                        Name           = subItem.Name,
                        NavigateUrl    = subItem.NavigateUrl,
                        PermissionCode = subItem.PermissionCode
                    });
                }
                model.Items.Add(menuItem);
            }

            return(View(model));
        }
        public ActionResult LeftNavigation()
        {
            if (_workContext.User == null)
            {
                return(View(new Menu()));
            }

            string         strPageVirtualUrl = _webHelper.GetThisPageVirtualUrl().ToLowerInvariant().Trim();
            User           user           = _workContext.User;
            PermissionMenu permissionMenu = user.Menu;

            var model = new Menu();

            foreach (var item in permissionMenu.Items)
            {
                MenuItem menuItem = new MenuItem
                {
                    Name           = item.Name,
                    NavigateUrl    = item.NavigateUrl,
                    PermissionCode = item.PermissionCode,
                    IsActive       = !item.NavigateUrl.IsNullOrEmpty() && item.NavigateUrl.ToLowerInvariant().Trim().Equals(strPageVirtualUrl)
                };

                foreach (var subItem in item.SubItems)
                {
                    var tmpMenuItem = new MenuItem
                    {
                        Name           = subItem.Name,
                        NavigateUrl    = subItem.NavigateUrl,
                        PermissionCode = subItem.PermissionCode,
                        IsActive       =
                            !subItem.NavigateUrl.IsNullOrEmpty() &&
                            subItem.NavigateUrl.ToLowerInvariant().Trim().Equals(strPageVirtualUrl)
                    };

                    if (!tmpMenuItem.IsActive)
                    {
                        var permissionItem = user.Permissions.FirstOrDefault(p => !p.NavigateUrl.IsNullOrWhiteSpace() && p.NavigateUrl.ToLowerInvariant().Equals(strPageVirtualUrl));
                        if (permissionItem != null)
                        {
                            permissionItem = user.Permissions.FirstOrDefault(p => p.ModuleId == permissionItem.ParentID);
                            if (permissionItem != null && subItem.ModuleId == permissionItem.ModuleId)
                            {
                                tmpMenuItem.IsActive = true;
                            }
                        }
                    }

                    menuItem.SubItems.Add(tmpMenuItem);
                    if (!menuItem.IsActive)
                    {
                        menuItem.IsActive = tmpMenuItem.IsActive;
                    }
                }
                model.Items.Add(menuItem);
            }

            return(View(model));
        }
Example #3
0
        /// <summary>
        /// 获取权限菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <Result <PermissionMenu> > Get(long id)
        {
            PermissionMenu permissionMenu = await _menuRepositories.GetPermissionMenuAsync(id);

            if (permissionMenu == null)
            {
                return(Result <PermissionMenu> .ReFailure(ResultCodes.PermissionMenuNotExist));
            }
            return(Result <PermissionMenu> .ReSuccess(permissionMenu));
        }
Example #4
0
        /// <summary>
        /// 删除权限菜单
        /// </summary>
        /// <param name="permissionMenu"></param>
        /// <returns></returns>
        public async Task <Result> Delete(PermissionMenu permissionMenu)
        {
            bool isDelete = await _menuRepositories.Delete(permissionMenu);

            if (!isDelete)
            {
                return(Result.ReFailure(ResultCodes.PermissionMenuDeleteError));
            }

            return(Result.ReSuccess());
        }
Example #5
0
        public static User ToLocal(this UserInfo userInfo)
        {
            var user = new User
            {
                Birthday     = userInfo.UserBaseInfo.Birthday,
                CompanyID    = userInfo.UserBaseInfo.CompanyID,
                CompanyName  = userInfo.UserBaseInfo.CompanyName,
                Duty         = userInfo.UserBaseInfo.Duty,
                Email        = userInfo.UserBaseInfo.Email,
                Enabled      = userInfo.UserBaseInfo.Enabled,
                IPAddress    = userInfo.UserBaseInfo.IPAddress,
                IsSuperAdmin = userInfo.UserBaseInfo.IsSuperAdmin,
                Mobile       = userInfo.UserBaseInfo.Mobile,
                OICQ         = userInfo.UserBaseInfo.OICQ,
                RealName     = userInfo.UserBaseInfo.RealName,
                RoleID       = userInfo.UserBaseInfo.RoleID,
                Sex          = userInfo.UserBaseInfo.Sex,
                SystemCode   = userInfo.UserBaseInfo.SystemCode,
                Title        = userInfo.UserBaseInfo.Title,
                UserUame     = userInfo.UserBaseInfo.UserName,
            };

            IList <PermissionMenuMenuItem> lstMenuItem     = new List <PermissionMenuMenuItem>();
            IList <PermissionMenuMenuItem> lstRootMenuItem = new List <PermissionMenuMenuItem>();

            userInfo.PermissionList.Each(p =>
            {
                var menuItem = p.ToLocal <PermissionMenuMenuItem>();
                if (p.IsMenu)
                {
                    if (p.ParentID == 0)
                    {
                        lstRootMenuItem.Add(menuItem);
                    }
                    else
                    {
                        lstMenuItem.Add(menuItem);
                    }
                }
                user.Permissions.Add(menuItem);
            });
            var menu = new PermissionMenu();

            user.Menu = menu;
            foreach (var rootMenuItem in lstRootMenuItem)
            {
                InitPermissionMenuItem(rootMenuItem, lstMenuItem);

                menu.Items.Add(rootMenuItem);
            }

            return(user);
        }
Example #6
0
        public List <PermissionMenu> GetMenu(long roleId, string menuType = "menu")
        {
            var listAll = _client.Queryable <Sys_rolemenu, Sys_menu>
                              ((s, c) => new object[] {
                JoinType.Left, s.MenuId == c.MenuId,
            })
                          .Select((s, c) => new
            {
                RoleId = s.RoleId.ToString(),
                c.IsDel,
                c.MenuName,
                c.MenuUrl,
                c.MenuType,
                c.MenuIcon,
                c.MenuParent,
                c.Status,
                c.MenuId,
                c.Sort
            }).MergeTable().Where((s) => s.IsDel == 1 && s.MenuType == menuType && s.Status == 1 && s.RoleId == roleId.ToString()).OrderBy(s => s.Sort).ToList();
            var listParent            = listAll.Where(s => s.MenuParent == -1).ToList();
            List <PermissionMenu> ret = new List <PermissionMenu>();

            listParent.ForEach(p =>
            {
                PermissionMenu permissionMenu = PermissionMenu.Create(new Sys_menu
                {
                    MenuId     = p.MenuId,
                    Status     = p.Status,
                    MenuIcon   = p.MenuIcon,
                    MenuName   = p.MenuName,
                    MenuParent = p.MenuParent,
                    MenuType   = p.MenuType,
                    MenuUrl    = p.MenuUrl,
                });
                permissionMenu.Children = listAll
                                          .Where(c => c.MenuParent == p.MenuId)
                                          .Select(m => new PermissionMenu()
                {
                    Id       = m.MenuId.ToString(),
                    Name     = m.MenuName,
                    Icon     = m.MenuIcon,
                    Url      = m.MenuUrl,
                    ParentId = m.MenuParent.ToString()
                }).ToList();
                ret.Add(permissionMenu);
            });
            return(ret);
        }
Example #7
0
        /// <summary>
        /// 修改权限菜单
        /// </summary>
        /// <param name="permissionMenu"></param>
        /// <returns></returns>
        public async Task <Result> Modify(PermissionMenu permissionMenu)
        {
            if (await _menuRepositories.GetEntity(f =>
                                                  (f.Id != permissionMenu.Id && f.Title.Equals(permissionMenu.Title)) || (f.Id != permissionMenu.Id && f.MenuUrl.Equals(permissionMenu.MenuUrl))) != null)
            {
                return(Result.ReFailure(ResultCodes.PermissionMenuTitleOrUrlExist));
            }
            bool isUpdate = await _menuRepositories.Update(permissionMenu);

            if (!isUpdate)
            {
                return(Result.ReFailure(ResultCodes.PermissionMenuUpdateError));
            }

            return(Result.ReSuccess());
        }
Example #8
0
        /// <summary>
        /// 创建权限菜单
        /// </summary>
        /// <param name="permissionMenu"></param>
        /// <returns></returns>
        public async Task <Result> Create(PermissionMenu permissionMenu)
        {
            // 判断权限菜单标题或地址是否重复了
            if (await _menuRepositories.GetEntity(f =>
                                                  f.Title.Equals(permissionMenu.Title) || f.MenuUrl.Equals(permissionMenu.MenuUrl)) != null)
            {
                return(Result.ReFailure(ResultCodes.PermissionMenuTitleOrUrlExist));
            }
            // 添加权限菜单
            bool isAdd = await _menuRepositories.Add(permissionMenu);

            if (!isAdd)
            {
                return(Result.ReFailure(ResultCodes.PermissionMenuCreateError));
            }
            return(Result.ReSuccess());
        }
Example #9
0
        public List <PermissionMenu> GetMenu()
        {
            var permissionMenus   = _menuServices.QueryableToList(c => c.IsDel == 1 && c.MenuType == "menu" && c.Status == 1);
            var parentPermissions = permissionMenus.Where(a => a.MenuParent == -1).ToList();
            var ret = new List <PermissionMenu>();

            parentPermissions.ForEach(p =>
            {
                PermissionMenu permissionMenu = PermissionMenu.Create(p);
                permissionMenu.Children       = permissionMenus
                                                .Where(c => c.MenuParent == p.MenuId)
                                                .Select(m => new PermissionMenu()
                {
                    Id       = m.MenuId.ToString(),
                    Name     = m.MenuName,
                    Icon     = m.MenuIcon,
                    Url      = m.MenuUrl,
                    ParentId = m.MenuParent.ToString()
                }).ToList();
                ret.Add(permissionMenu);
            });
            return(ret);
        }