private string BuildMenuItem(PageMenuDto pageMenu, BuildMenuOption option = null) { var menuItem = ""; var page = AccessiblePagesForUser.FirstOrDefault(x => x.ID == pageMenu.PageID); if (page == null) { return(menuItem); } var listItemClass = LISTITEMCLASS; if (option != null && !option.SelectedListItemClass.IsNullOrEmpty() && option.CurrentControllerName == page.Controller) { listItemClass += SELECTEDLISTITEMCLASS; } if (page.Area.IsNullOrEmpty() && page.Controller.IsNullOrEmpty()) { menuItem += string.Format("<li{0}><a{1} href=\"{2}\">{3}</a>", listItemClass, HYPERLINKCLASS, page.Action, page.Title); } else { menuItem += string.Format("<li{0}><a{1} href=\"{2}\">{3}</a>", listItemClass, HYPERLINKCLASS, Url.Action(page.Action, page.Controller, new { area = page.Area }), page.Title); } if (PageMenus.Any(x => x.ParentID == pageMenu.ID && x.ID != pageMenu.ID)) { menuItem += string.Format("<ul{0}>", SUBLISTCLASS); var subMenuItems = PageMenus.Where(x => x.ParentID == pageMenu.ID && x.ID != pageMenu.ID); menuItem = subMenuItems.Aggregate(menuItem, (current, item) => current + BuildMenuItem(item, option)); menuItem += "</ul>"; } menuItem += "</li>"; return(menuItem); }
protected string BuildMenuList(string groupName, BuildMenuOption option = null) { if (PageMenus == null || !PageMenus.Any() || AccessiblePagesForUser == null || !AccessiblePagesForUser.Any()) { return(string.Empty); } var menu = ""; menu = PageMenus.Where(x => x.GroupName == groupName && x.ParentID == 0).Aggregate(menu, (current, pageMenu) => current + BuildMenuItem(pageMenu, option)); return(MergeMenuWithOption(menu, option)); }