Esempio n. 1
0
        public async Task <IActionResult> GetAllProducts()
        {
            List <Product> products = await _robotoRepo.GetProducts();

            ProductListingVM productListVM = new ProductListingVM
            {
                Products = products
            };

            return(View(productListVM));
        }
Esempio n. 2
0
        /// <summary>
        /// populates the list of items to shop and allows users to search for a specific item by name
        /// </summary>
        /// <param name="searchString">the name of the item to search for</param>
        /// <returns>a list of items on search parameters (shows all products if search string is null)</returns>
        public IActionResult Index(string searchString)
        {
            var products = _robotoRepo.GetProducts().Result.AsQueryable();

            if (!String.IsNullOrEmpty(searchString))
            {
                products = products.Where(s => s.Name.ToLower().Contains(searchString.ToLower()));
            }

            ProductListingVM productListVM = new ProductListingVM
            {
                Products = products.ToList()
            };

            return(View(productListVM));
        }