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))); //передаем список провайдеру для создания карты сайта
        }
Example #2
0
        private List <BrandViewModel> GetBrands(int?currentBrandId)
        {
            IEnumerable <BrandDTO> allBrands     = _catalogData.GetBrands();
            List <BrandViewModel>  allBrandsList = allBrands.Select(brand => new BrandViewModel
            {
                Id             = brand.Id,
                Name           = brand.Name,
                Order          = brand.Order,
                CurrentBrandId = (currentBrandId.HasValue ? brand.Id == currentBrandId.Value : false)
            }).OrderBy(b => b.Order).ToList();

            foreach (BrandViewModel brand in allBrandsList)
            {
                brand.ProductsCount = GetProductsCount(brand.Id);
            }

            return(allBrandsList);
        }
        private List <BrandViewModel> GetBrands()
        {
            IQueryable <Brand>    allBrands     = _catalogData.GetBrands();
            List <BrandViewModel> allBrandsList = allBrands.Select(brand => new BrandViewModel
            {
                Id    = brand.Id,
                Name  = brand.Name,
                Order = brand.Order,
                //ProductsCount = GetProductsCount(brand.Id) //так выдает ошибку "There is already an open DataReader associated with this Command which must be closed first"
            }).OrderBy(b => b.Order).ToList();

            foreach (BrandViewModel brand in allBrandsList)
            {
                brand.ProductsCount = GetProductsCount(brand.Id);
            }

            return(allBrandsList);
        }
Example #4
0
 public IEnumerable <BrandDTO> GetBrands()
 {
     return(_catalogData.GetBrands());
 }