public async Task SetActiveAsync(string path) { _logger.LogDebug("Try set breadcrumb"); CurrentBreadcrumb = await _memoryCache.GetOrCreateAsync(GetCacheNameForPath(path), async entry => { var currentNodes = await _matchSitemapNode.FindByPath(path); var firstCurrentNode = currentNodes.FirstOrDefault(); if (firstCurrentNode != null) { //Build breadcrumb var breadcrumb = new BreadcrumbDto { Id = firstCurrentNode.Id, Name = firstCurrentNode.Name, Path = firstCurrentNode.Path, //TODO build path }; var node = firstCurrentNode; var currentBreadcrumb = breadcrumb; while (node.ParentId.HasValue) { var parent = await _sitemapNodeRepository.GetAsync(node.ParentId.Value); var parentBreadcrumb = new BreadcrumbDto { Id = parent.Id, Name = parent.Name, Path = parent.Path, //TODO build path }; currentBreadcrumb.Parent = parentBreadcrumb; currentBreadcrumb = parentBreadcrumb; node = parent; } return(breadcrumb); } return(BreadcrumbDto.Default); }); ChangeActive?.Invoke(this, new ChangeBreadcrumbEventArgs { CurrentBreadcrumb = CurrentBreadcrumb }); }
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 }); } }