Example #1
0
        public QNZ.Data.Menu GetCurrenMenu(int categoryId, ViewContext viewContext, List <QNZ.Data.Menu> menus)
        {
            var controller = viewContext.RouteData.Values["controller"].ToString();
            var action     = viewContext.RouteData.Values["action"].ToString();

            var    area = string.Empty;
            object areaObj;

            if (viewContext.RouteData.Values.TryGetValue("area", out areaObj))
            {
                area = areaObj.ToString();
            }
            //string area = Site.CurrentArea(), controller = Site.CurrentController(), action = Site.CurrentAction();
            // var menus = await _context.Menus.Where(m => m.CategoryId == categoryId).ToListAsync();

            QNZ.Data.Menu vMenu = menus?.FirstOrDefault(m => area.Equals(m.Area, StringComparison.OrdinalIgnoreCase) &&
                                                        controller.Equals(m.Controller, StringComparison.OrdinalIgnoreCase) &&
                                                        action.Equals(m.Action, StringComparison.OrdinalIgnoreCase));


            if (vMenu == null)
            {
                return(null);
            }

            if (vMenu.Active || vMenu.MenuType == (short)MenuType.PAGE)
            {
                return(vMenu);
            }

            return(RecursiveLoadMenu(vMenu.ParentId, menus));
        }
Example #2
0
        public async Task <List <QNZ.Data.Menu> > CurrenMenuCrumbsAsync(int categoryId, ViewContext viewContext)
        {
            var controller = viewContext.RouteData.Values["controller"].ToString();
            var action     = viewContext.RouteData.Values["action"].ToString();

            var    area = string.Empty;
            object areaObj;

            if (viewContext.RouteData.Values.TryGetValue("area", out areaObj))
            {
                area = areaObj.ToString();
            }
            // string area = Site.CurrentArea(), controller = Site.CurrentController(), action = Site.CurrentAction();
            //string actionName = ControllerContext.RouteData.Values["action"].ToString();
            //string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
            //var aa= ControllerContext.ActionDescriptor.ActionName

            var rource = await GetShowMenusAsync(categoryId);

            List <QNZ.Data.Menu> menus = new List <QNZ.Data.Menu>();

            QNZ.Data.Menu vMenu = rource.FirstOrDefault(m => area.Equals(m.Area, StringComparison.OrdinalIgnoreCase) &&
                                                        controller.Equals(m.Controller, StringComparison.OrdinalIgnoreCase) &&
                                                        action.Equals(m.Action, StringComparison.OrdinalIgnoreCase));

            if (vMenu != null)
            {
                await RecursiveLoadAsync(vMenu, menus);
            }

            return(menus);
        }
Example #3
0
        private QNZ.Data.Menu RecursiveLoadMenu(int?parentId, List <QNZ.Data.Menu> menus)
        {
            // var menus = GetAllMenusByCategoryId(SettingsManager.Menu.BackMenuCId);

            QNZ.Data.Menu vMenu = menus.FirstOrDefault(m => m.ParentId == parentId && m.MenuType == (short)MenuType.PAGE);

            if (vMenu.Parent != null && (vMenu.Parent.MenuType != (short)MenuType.PAGE || !vMenu.Parent.Active))
            {
                return(RecursiveLoadMenu(vMenu.ParentId, menus));
            }
            return(vMenu.Parent);
        }
Example #4
0
        /// <summary>
        /// 递归获取父项
        /// </summary>
        /// <param name="vMenu"></param>
        /// <param name="Parents"></param>
        private async Task RecursiveLoadAsync(QNZ.Data.Menu vMenu, List <QNZ.Data.Menu> Parents)
        {
            Parents.Insert(0, vMenu);
            if (vMenu.ParentId != null)
            {
                var rource = await GetShowMenusAsync(vMenu.CategoryId);

                QNZ.Data.Menu parentMenu = rource.FirstOrDefault(m => m.Id == vMenu.ParentId);
                if (parentMenu != null)
                {
                    await RecursiveLoadAsync(parentMenu, Parents);
                }
            }
        }