IEnumerable <SWIMenuItem> getWebMenu() { var result = new List <SWIMenuItem>(); foreach (var view in WebUser.GetMenuReportViews()) { var menuNames = view.MenuPath.Split('/').Where(i => !string.IsNullOrEmpty(i)).ToList(); if (menuNames.Count > 0) { var menuItem = new SWIMenuItem() { path = view.Report.RelativeFilePath, name = view.MenuReportViewName, viewGUID = view.GUID }; menuNames.RemoveAt(menuNames.Count - 1); if (menuNames.Count > 0) { getMenuFromNames(result, menuNames, menuItem); } else { result.Add(menuItem); } } } return(result.OrderBy(i => i.name)); }
SWIMenuItem getMenuFromNames(List <SWIMenuItem> parents, List <string> names, SWIMenuItem menuItem) { var result = parents.FirstOrDefault(i => i.name == names[0] && i.path == null); if (result == null) { result = new SWIMenuItem() { name = names[0] }; parents.Add(result); parents = parents.OrderBy(i => i.name).ToList(); } if (names.Count > 1) { names.RemoveAt(0); result = getMenuFromNames(result.items, names, menuItem); } else { result.items.Add(menuItem); result.items = result.items.OrderBy(i => i.name).ToList(); } return(result); }