Exemplo n.º 1
0
 public async Task <IEnumerable <ProductViewModel> > GetByMainCategoryAsync(MainStoreCategories category) =>
 await DbContext
 .Products
 .Include(p => p.Category)
 .Where(p => p.Category.StoreCategory == category)
 .ProjectTo <ProductViewModel>(Mapper.ConfigurationProvider)
 .ToListAsync();
Exemplo n.º 2
0
        public async Task <IEnumerable <ProductViewModel> > GetByMainCategoryAndWordAsync(
            MainStoreCategories category,
            string searchedWord)
        {
            if (category == MainStoreCategories.All)
            {
                return(await DbContext.Products
                       .Include(p => p.Category)
                       .Where(p => p.Name
                              .ToLower()
                              .Contains(searchedWord.ToLower()))
                       .ProjectTo <ProductViewModel>(Mapper.ConfigurationProvider)
                       .ToListAsync());
            }

            return(await DbContext.Products
                   .Include(p => p.Category)
                   .Where(p => p.Category.StoreCategory == category &&
                          p.Name.ToLower().Contains(searchedWord.ToLower()))
                   .ProjectTo <ProductViewModel>(Mapper.ConfigurationProvider)
                   .ToListAsync());
        }
 /// GET: /Products/SearchByCategoryAndWord
 /// <summary>
 /// Returns collection of Products by Category -> Main Store Category
 /// and searched word.
 /// It is visualized in the Products->Index view.
 /// </summary>
 /// <param name="category">Main Store Category</param>
 /// <param name="searchedWord"></param>
 public async Task <IActionResult> SearchByCategoryAndWord([FromQuery]
                                                           MainStoreCategories category,
                                                           string searchedWord) =>
 View(ProductsIndex, await _productsService.GetByMainCategoryAndWordAsync(category, searchedWord));
 /// GET: /Products/GetByMainCategory
 /// <summary>
 /// Returns collection of Products by Category -> Main Store Category.
 /// It is visualized in the Products->Index view.
 /// </summary>
 /// <param name="category">Main Store Category</param>
 public async Task <IActionResult> GetByMainCategory(MainStoreCategories category) =>
 View(ProductsIndex, await _productsService.GetByMainCategoryAsync(category));