Пример #1
0
        private static Menu CreateAreaMenuItemFromController(Type controller, MenuItemAttribute menuItemAttribute)
        {
            string area           = GetAreaNameForController(controller);
            var    controllerName = controller.Name.Replace("Controller", "");
            var    menu           = new Menu()
            {
                Name = menuItemAttribute.Title ?? controllerName,
                ControllerFullName = controller.FullName,
                Order   = menuItemAttribute.Order,
                CssIcon = menuItemAttribute.CssIcon
            };

            if (menuItemAttribute.IsClickable)
            {
                menu.Url = CreateActionPath(area, controllerName, menuItemAttribute.Action ?? "Index");
            }
            var submenus = new List <SubMenu>(); //The actions under the controller becomes submenu

            controller.GetMethods().ToList().ForEach(method =>
            {
                menuItemAttribute = method.GetCustomAttribute <MenuItemAttribute>();
                if (menuItemAttribute == null)
                {
                    return;
                }
                if (!UserHasAccess(method.GetCustomAttribute <AuthorizedRoleAttribute>()))
                {
                    return;
                }
                var submenu = new SubMenu()
                {
                    Name    = menuItemAttribute.Title ?? method.Name,
                    Order   = menuItemAttribute.Order,
                    CssIcon = menuItemAttribute.CssIcon
                };
                if (menuItemAttribute.IsClickable)
                {
                    submenu.Url = CreateActionPath(area, controllerName, method.Name);
                }
                submenus.Add(submenu);
            });
            menu.SubMenus = submenus.OrderBy(m => m.Order).ToList();
            return(menu);
        }
Пример #2
0
        private static Menu CreateAreaMenuItemFromAction(Type controller, MethodInfo method, MenuItemAttribute menuItemAttribute)
        {
            string area = GetAreaNameForController(controller);

            var menu = new Menu()
            {
                Name = menuItemAttribute.Title ?? method.Name,
                ControllerFullName = controller.FullName,
                Order   = menuItemAttribute.Order,
                CssIcon = menuItemAttribute.CssIcon
            };

            if (menuItemAttribute.IsClickable)
            {
                menu.Url = CreateActionPath(area, controller.Name.Replace("Controller", ""), method.Name);
            }
            return(menu);
        }