private static PageNavigation BuildPageNavigation( IDictionary <string, PageMetadataModel> pageList ) { var pathList = pageList.Keys; var root = new PageNavigationModel { Id = "root", Title = "root", IsFolder = true, ChildrenAsList = new List <PageNavigationModel>(), }; foreach (var path in pathList) { AddNavigationModelToNode( pageList, root, path ); } root.ChildrenAsList = root.ChildrenAsList?.OrderBy( a => a.Title )?.OrderBy( a => a.ChildrenAsList != null )?.ToList() ?? new List <PageNavigationModel>(); return(root); }
protected Page(PresentationNavigationModel presentationNavigation, string tag, string title) { _presentationNavigation = presentationNavigation; _tag = tag; _title = title; _pageNavigation = new PageNavigationModel(); }
protected Page(PresentationNavigationModel presentationNavigation, string tag, string title) { _presentationNavigation = presentationNavigation; _tag = tag; _title = title; _pageNavigation = new PageNavigationModel(); }
private static void AddNavigationModelToNode( IDictionary <string, PageMetadataModel> pageList, PageNavigationModel root, string path ) { var splitPath = path.Split( "/", StringSplitOptions.RemoveEmptyEntries ).ToList(); var node = splitPath.Last(); var parentList = splitPath.Take( splitPath.Count - 1 ); var parent = root; foreach (var newParentPath in parentList) { var newParent = default(PageNavigationModel); if (parent.Children.Any( a => a.Id == newParentPath ) && parent.Children.First( a => a.Id == newParentPath ).IsFolder) { // Set newParent to already existing newParent = (PageNavigationModel)parent.Children.First( a => a.Id == newParentPath ); } else if (parent.Children.Any( a => a.Id == newParentPath ) && !parent.Children.First( a => a.Id == newParentPath ).IsFolder) { // Update Parent Node to Parent Folder // And add Node to Folder newParent = (PageNavigationModel)parent.Children.First( a => a.Id == newParentPath ); var newParentAsNode = new PageNavigationModel { Id = newParent.Id, Title = newParent.Title, Route = newParent.Route, }; // Set Parent to Folder newParent.IsFolder = true; newParent.Route = string.Empty; newParent.ChildrenAsList = new List <PageNavigationModel> { newParentAsNode }; } else { newParent = new PageNavigationModel { Id = newParentPath, Title = newParentPath, IsFolder = true, ChildrenAsList = new List <PageNavigationModel>(), }; parent.ChildrenAsList.Add(newParent); } parent = newParent; parent.ChildrenAsList = parent.ChildrenAsList?.OrderBy( a => a.Title )?.OrderBy( a => a.ChildrenAsList != null )?.ToList() ?? new List <PageNavigationModel>(); } parent.ChildrenAsList.Add( // Add Node new PageNavigationModel { Id = node, Title = pageList.First( page => page.Key == path ).Value.Title ?? node, Route = path, } ); parent.ChildrenAsList = parent.ChildrenAsList?.OrderBy( a => a.Title )?.OrderBy( a => a.ChildrenAsList != null )?.ToList() ?? new List <PageNavigationModel>(); }