コード例 #1
0
        public async Task <List <Product> > GetWithFilters(CatalogFilters filters)
        {
            var products = filters.SortByPrice
                ? _dbContext.Product.OrderBy(product => product.Price).AsQueryable()
                : _dbContext.Product.OrderByDescending(product => product.Price).AsQueryable();

            if (!string.IsNullOrEmpty(filters.NameContains))
            {
                products = products.Where(product => product.Name.Contains(filters.NameContains));
            }

            if (filters.PriceHigherThan != null)
            {
                products = products.Where(product => product.Price >= filters.PriceHigherThan);
            }

            if (filters.PriceLowerThan != null)
            {
                products = products.Where(product => product.Price <= filters.PriceLowerThan);
            }

            if (filters.Genders != null)
            {
                products = products.Where(product => filters.Genders.Contains(product.Gender));
            }

            if (filters.Categories != null)
            {
                products = products.Where(product => filters.Categories.Contains(product.Category));
            }

            if (filters.Brands != null)
            {
                products = products.Where(product => filters.Brands.Contains(product.Brand));
            }

            if (filters.Colors != null)
            {
                products = products.Where(product => filters.Colors.Contains(product.Color));
            }

            if (filters.Sizes != null)
            {
                var ids = _dbContext.ProductSize.Where(ps => filters.Sizes.Contains(ps.Size))
                          .Select(ps => ps.ProductId);
                products = products.Where(product => ids.Contains(product.Id));
            }

            return(await products.Where(product => _dbContext.ProductSize.Any(ps => ps.ProductId == product.Id && ps.Quantity > 0)).ToListAsync());
        }
コード例 #2
0
ファイル: SectionPage.cs プロジェクト: JumperIn/Totto
 /// <summary>
 /// Создает экземпляр и инициализирует поля класса.
 /// </summary>
 public SectionPage
 (
     SeoData seo,
     Navigation navigation,
     List <Breadcrumb> breadcrumbs,
     List <Product> products,
     int productsCount,
     CatalogFilters filters,
     Pagination pagination
 ) : base(seo, navigation, breadcrumbs)
 {
     SectionTitle  = Breadcrumbs.LastOrDefault()?.Title;
     Products      = products.Select(p => new ProductCard(p)).ToList();
     ProductsCount = productsCount;
     Filters       = filters;
     Pagination    = pagination;
 }
コード例 #3
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));
        }
コード例 #4
0
ファイル: CatalogController.cs プロジェクト: Olya-hu/Shop
 public async Task <IActionResult> Index([FromQuery] CatalogFilters filters)
 {
     return(ModelState.IsValid ? View(await _catalog.GetWithFilters(filters)) : ValidationProblem());
 }