internal void SetChildren(Dto.MenuNodeDto currentNode, IEnumerable <Dto.MenuNodeDto> allNodes) { var children = allNodes.Where(x => x.ParentId == currentNode.Id); if (children.Any() == false) { return; } currentNode.Children = children; foreach (var child in children) { child.Parent = currentNode; SetChildren(child, allNodes); } }
private async Task SetActiveNodeWithIndexedSitemapNode(IDictionary <Guid, Dto.MenuNodeDto> indexSitemap, string path) { //Disable all foreach (var indexNode in indexSitemap) { indexNode.Value.SetActive(false); } var currentActiveSitemapNodes = await _matchSitemapNode.FindByPath(path); if (currentActiveSitemapNodes == null || currentActiveSitemapNodes.Any() == false) { ChangeActiveNode?.Invoke(this, new ChangeActiveNodeEventArgs { FoundActiveNode = false, ActiveNode = null }); } else { var currentFirstNode = currentActiveSitemapNodes.First(); Dto.MenuNodeDto activeNode = null; if (indexSitemap.ContainsKey(currentFirstNode.Id)) { activeNode = indexSitemap[currentFirstNode.Id]; } else if (currentFirstNode.ParentId.HasValue && indexSitemap.ContainsKey(currentFirstNode.ParentId.Value)) { activeNode = indexSitemap[currentFirstNode.ParentId.Value]; } else { _logger.LogDebug($"Not found any node for sitemap id: {currentFirstNode.Id} or parent id {currentFirstNode.ParentId}"); } activeNode?.SetActive(true); _logger.LogDebug($"Set active node: {activeNode}"); ChangeActiveNode?.Invoke(this, new ChangeActiveNodeEventArgs { FoundActiveNode = activeNode != null, ActiveNode = activeNode }); } }