コード例 #1
0
        public async Task <IEnumerable <BreadcrumbDto> > GetFlatAsync()
        {
            var list = new List <BreadcrumbDto>();

            var current = CurrentBreadcrumb;

            list.Add(new BreadcrumbDto
            {
                Id     = current.Id,
                Name   = current.Name,
                Parent = null,
                Path   = current.Path
            });

            while (current.Parent != null)
            {
                current = current.Parent;

                var item = new BreadcrumbDto
                {
                    Id     = current.Id,
                    Name   = current.Name,
                    Parent = null,
                    Path   = current.Path
                };

                list.Add(item);
            }

            list.Reverse();

            return(await Task.FromResult(list));
        }
コード例 #2
0
        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
            });
        }