예제 #1
0
        public List <Product> Filter
        (
            string categoryUrl,
            string subcategoryUrl,
            string groupUrl,
            CatalogCountItems count,
            CatalogSortingType sorting,
            int page,
            string filters,
            int minPrice,
            int maxPrice,
            string manufacturer,
            ProductType type
        )
        {
            ProductCategory    category    = catalogRepository.GetCategory(categoryUrl);
            ProductSubcategory subcategory = catalogRepository.GetSubcategory(subcategoryUrl);
            ProductGroup       group       = catalogRepository.GetGroup(groupUrl);

            int categoryId    = category != null ? category.Id : 0;
            int subcategoryId = subcategory != null ? subcategory.Id : 0;
            int groupId       = group != null ? group.Id : 0;

            if (category == null)
            {
                return(null);
            }

            int countItems = GetPageCountByItems(count);

            List <Product> products = productsRepository.GetProducts(categoryId, subcategoryId, groupId);

            IEnumerable <Product> filteredProducts = FilterByCategories(products, filters);

            filteredProducts = FilterByPrice(filteredProducts, minPrice, maxPrice);
            filteredProducts = FilterByManufacturer(filteredProducts, manufacturer);
            filteredProducts = SortByCatalogType(filteredProducts, sorting);
            filteredProducts = FilterByProductType(filteredProducts, type);
            filteredProducts = GetProductByPage(filteredProducts, countItems, page);

            List <Product> finalProducts = filteredProducts.ToList();

            return(finalProducts);
        }
예제 #2
0
        public IActionResult GetProductCards
        (
            string categoryUrl         = "",
            string subcategoryUrl      = "",
            string groupUrl            = "",
            CatalogCountItems count    = CatalogCountItems.Small,
            CatalogSortingType sorting = CatalogSortingType.AscendingTitle,
            int page            = 1,
            string filters      = "",
            int minPrice        = 0,
            int maxPrice        = int.MaxValue,
            string manufacturer = "",
            ProductType type    = ProductType.Normal
        )
        {
            if (string.IsNullOrEmpty(categoryUrl))
            {
                return(BadRequest());
            }

            ProductCategory    category    = catalogRepository.GetCategory(categoryUrl);
            ProductSubcategory subcategory = catalogRepository.GetSubcategory(subcategoryUrl);
            ProductGroup       group       = catalogRepository.GetGroup(groupUrl);

            int countItems = productsFilterService.GetPageCountByItems(count);

            List <Product> products = productsFilterService.Filter
                                      (
                categoryUrl, subcategoryUrl, groupUrl,
                count, sorting, page,
                filters,
                minPrice, maxPrice,
                manufacturer, type
                                      );

            List <ProductCard> productCards = products
                                              .Select(product => new ProductCard(product))
                                              .ToList();

            return(Ok(productCards));
        }
예제 #3
0
        public int GetPageCountByItems(CatalogCountItems count)
        {
            int countItems;

            switch (count)
            {
            case CatalogCountItems.Medium:
                countItems = showByCounts[1];
                break;

            case CatalogCountItems.Large:
                countItems = showByCounts[2];
                break;

            default:
                countItems = showByCounts[0];
                break;
            }

            return(countItems);
        }
예제 #4
0
        public IActionResult Section
        (
            string categoryUrl         = "",
            string subcategoryUrl      = "",
            string groupUrl            = "",
            CatalogCountItems count    = CatalogCountItems.Small,
            CatalogSortingType sorting = CatalogSortingType.AscendingTitle,
            int page            = 1,
            string filters      = "",
            int minPrice        = 0,
            int maxPrice        = int.MaxValue,
            string manufacturer = "",
            ProductType type    = ProductType.Normal
        )
        {
            if (string.IsNullOrEmpty(categoryUrl))
            {
                return(NotFound());
            }

            Navigation navigation = commonRepository.GetNavigation();
            SeoData    seo        = commonRepository.GetSeo("catalog");

            ProductCategory    category    = catalogRepository.GetCategory(categoryUrl);
            ProductSubcategory subcategory = catalogRepository.GetSubcategory(subcategoryUrl);
            ProductGroup       group       = catalogRepository.GetGroup(groupUrl);

            if (category == null)
            {
                return(NotFound());
            }

            int countItems = productsFilterService.GetPageCountByItems(count);

            List <Product> products = productsFilterService.Filter
                                      (
                categoryUrl, subcategoryUrl, groupUrl,
                count, sorting, page,
                filters,
                minPrice, maxPrice,
                manufacturer, type
                                      );

            List <Breadcrumb> breadcrumbs = GetBreadcrumbs(category, subcategory, group);

            var catalogFilters = new CatalogFilters()
            {
                MinPrice      = (int)products.Min(x => x.Price),
                MaxPrice      = (int)products.Max(x => x.Price),
                Manufacturers = products.Any() ?
                                products.Select(x => x.Manufacturer).Distinct(new ManufacturerEqualityComparer()).ToList() :
                                new List <Manufacturer>(),
                CategoryFilters = new List <CategoryFilter>()
                {
                    new CategoryFilter("Категория 1", new List <CategoryFilterItem>()
                    {
                        new CategoryFilterItem(1, "Увлажняющие", "cat-1-uvlaj"),
                        new CategoryFilterItem(2, "Питательные", "cat-1-pitatel"),
                        new CategoryFilterItem(3, "Натуральные", "cat-1-natural"),
                        new CategoryFilterItem(4, "Дневные", "cat-1-den"),
                        new CategoryFilterItem(5, "Ночные", "cat-1-noch")
                    }),
                    new CategoryFilter("Категория 2", new List <CategoryFilterItem>()
                    {
                        new CategoryFilterItem(6, "Антивозрастные", "cat-2-antivozrast"),
                        new CategoryFilterItem(7, "Жирные", "cat-2-jirnie"),
                        new CategoryFilterItem(8, "Сухие", "cat-2-suhie"),
                        new CategoryFilterItem(9, "Невероятные", "cat-2-neveroyat"),
                        new CategoryFilterItem(10, "Чудесные", "cat-2-chudo")
                    })
                }
            };

            int pageCount   = products.Count() / countItems != 0 ? products.Count() / countItems : 1;
            var pagination  = new Pagination(page, pageCount);
            var sectionPage = new SectionPage(seo, navigation, breadcrumbs, products, products.Count, catalogFilters, pagination);

            return(View(sectionPage));
        }