Exemplo n.º 1
0
 private string RenderListItem(MenuItem menuItem, bool mainMenuItem = false)
 {
     return String.Format(@"
                                     <li {1}>
                                         <a href=""{2}""><i class="" fa {3}""></i> {0} </a>
                                     </li>
                           ",
                            mainMenuItem ? String.Format(@"<span class=""title"">{0}</span>", menuItem.ItemName) : menuItem.ItemName,
                            menuItem.IsActive ? @"class=""active""" : "",
                            UrlHelper.GenerateUrl("Default", menuItem.Action, menuItem.Controller, menuItem.RouteValues, RouteTable.Routes, HttpContext.Current.Request.RequestContext, false),
                            HtmlHelperExtensions.RenderClassName(menuItem.ItemIconClass.ToString()));
 }
Exemplo n.º 2
0
        private bool IsMenuItemActive(MenuItem menuItem)
        {
            bool found = false;
            RouteData routeData = HttpContext.Current.Request.RequestContext.RouteData;
            NameValueCollection queryString = HttpContext.Current.Request.QueryString;

            if (!found && menuItem.Action.Equals(routeData.Values["Action"].ToString(), StringComparison.InvariantCultureIgnoreCase) && menuItem.Controller.Equals(routeData.Values["Controller"].ToString(), StringComparison.InvariantCultureIgnoreCase))
            {
                found = true;
            }

            if (!found && menuItem.ActiveFilePaths != null && menuItem.ActiveFilePaths.Contains(HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath, StringComparer.InvariantCultureIgnoreCase))
            {
                found = true;
            }

            //Query string matching
            if (found && menuItem.RouteValues != null)
            {
                if (queryString.HasKeys())
                {
                    int numberMatchingQueryStringPairs = menuItem.RouteValues.Where(x => queryString.AllKeys.Contains(x.Key) && queryString[x.Key].Equals(x.Value.ToString(), StringComparison.InvariantCultureIgnoreCase)).Count();
                    if (numberMatchingQueryStringPairs == menuItem.RouteValues.Count)
                    {
                        found = true;
                    }
                    else
                    {
                        found = false;
                    }
                }
                else
                {
                    found = false;
                }
            }

            return found;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds a new menu item to a group.
        /// </summary>
        /// <param name="headGroup">The menu to add the menu item too</param>
        /// <param name="searchExpression">Where to add the menu item</param>
        /// <param name="menuItemToAdd">The menu item to add</param>
        /// <returns></returns>
        public MenuItem AddMenuItemToGroup(MenuGroup headGroup, Expression<Func<MenuGroup, bool>> searchExpression, MenuItem menuItemToAdd)
        {
            // Compiling the expression tree into a delegate.
            Func<MenuGroup, bool> expressionResult = searchExpression.Compile();

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

            if (expressionResult(headGroup))
            {
                headGroup.MenuItems.Add(menuItemToAdd);
                headGroup.MenuItems = headGroup.MenuItems.OrderBy(x => x.SortOrder).ThenBy(x => x.ItemName).ToList<MenuItem>();
                return menuItemToAdd;
            }

            foreach (MenuGroup item in headGroup.MenuSubGroups)
            {
                MenuItem result = AddMenuItemToGroup(item, searchExpression, menuItemToAdd);

                if (result != null)
                {
                    return result;
                }
            }

            return null;
        }