public IActionResult Index([FromServices] ICatalogData catalogData)
        {
            List <SitemapNode> nodes = new List <SitemapNode>   //составляем список статических узлов для передачи в карту сайта
            {
                new SitemapNode(Url.Action("Index", "Home")),
                new SitemapNode(Url.Action("ContactUs", "Home")),
                new SitemapNode(Url.Action("Index", "Blogs")),
                new SitemapNode(Url.Action("BlogSingle", "Blogs")),
                new SitemapNode(Url.Action("Shop", "Catalog")),
                new SitemapNode(Url.Action("Index", "WebAPITest")),
            };

            //добавляем к списку все страницы секций товаров
            nodes.AddRange(catalogData.GetSections().Select(section => new SitemapNode(Url.Action("Shop", "Catalog", new { sectionId = section.Id }))));

            //добавляем к списку все страницы брендов товаров
            foreach (var brand in catalogData.GetBrands())
            {
                nodes.Add(new SitemapNode(Url.Action("Shop", "Catalog", new { brandId = brand.Id })));
            }

            //добавляем к списку каждую страницу каждого товара
            foreach (var product in catalogData.GetProducts().Products)
            {
                nodes.Add(new SitemapNode(Url.Action("ProductDetails", "Catalog", new { product.Id })));
            }

            return(new SitemapProvider().CreateSitemap(new SitemapModel(nodes))); //передаем список провайдеру для создания карты сайта
        }
        private List <SectionViewModel> GetSections(int?currentSectionId)
        {
            IEnumerable <SectionDTO> allSections = _catalogData.GetSections();

            SectionDTO[]            parentSections     = allSections.Where(p => p.ParentId == null).ToArray();
            List <SectionViewModel> parentSectionsList = new List <SectionViewModel>();

            foreach (SectionDTO parent in parentSections)
            {
                parentSectionsList.Add(new SectionViewModel
                {
                    Id            = parent.Id,
                    Name          = parent.Name,
                    Order         = parent.Order,
                    ParentSection = null
                });
            }

            foreach (SectionViewModel parent in parentSectionsList)
            {
                IEnumerable <SectionDTO> childSections = allSections.Where(c => c.ParentId == parent.Id);

                foreach (SectionDTO child in childSections)
                {
                    if (child.Id == currentSectionId)
                    {
                        _currentParentSectionId = parent.Id;
                    }

                    parent.ChildSections.Add(new SectionViewModel
                    {
                        Id            = child.Id,
                        Name          = child.Name,
                        Order         = child.Order,
                        ParentSection = parent
                    });
                }

                parent.ChildSections = parent.ChildSections.OrderBy(c => c.Order).ToList();
            }

            parentSectionsList = parentSectionsList.OrderBy(c => c.Order).ToList();
            return(parentSectionsList);
        }
Exemple #3
0
 public IEnumerable <SectionDTO> GetSections()
 {
     return(_catalogData.GetSections());
 }