/// <summary>
        /// Searches for all products whose productName property contains the value specified in productName. If
        /// a categoryId is specified, we will restrict the search to products within the specified category.
        /// </summary>
        public async Task <ProductSearchResultsVM> SearchForProducts(string categoryId, string productName)
        {
            List <Product> retrievedProducts = await _repository.SearchForProducts(categoryId, productName);

            ProductSearchResultsVM results = CopyProductSearchResultsToViewModel(retrievedProducts);

            return(results);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> SearchForProducts(ProductSearchRequestVM searchRequest)
        {
            ViewBag.Categories = await _productService.GetAllCategories();

            //get our search results...
            ProductSearchResultsVM searchResults = await _productService.SearchForProducts(searchRequest.CategoryId, searchRequest.ProductName);

            ViewBag.SearchResults = searchResults;
            return(View("Index"));
        }
        private ProductSearchResultsVM CopyProductSearchResultsToViewModel(List <Product> products)
        {
            ProductSearchResultsVM resultsVM = new ProductSearchResultsVM();

            resultsVM.ProductResults = new List <ProductVM>();
            foreach (Product p in products)
            {
                resultsVM.ProductResults.Add(CopyProductToViewModel(p));
            }
            return(resultsVM);
        }