public async Task <IActionResult> GetAllProducts() { List <Product> products = await _robotoRepo.GetProducts(); ProductListingVM productListVM = new ProductListingVM { Products = products }; return(View(productListVM)); }
/// <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)); }
public IActionResult ProductListing(int GenderId = 0, int CategoryId = 0, string search = null) { if (HttpContext.GetLoggedUser() != null) { TempData["logged"] = "True"; } ProductListingVM hm = new ProductListingVM(); if (search != null) { hm.Rows = con.Products.Where(x => x.ProductName.Contains(search)).Select(x => new ProductListingVM.Row { Price = x.Price.ToString(), ProductName = x.ProductName, CategoryId = x.CategoryId, GenderId = x.GenderId, ShortDescription = x.ShortDescription, Route = x.ImageRoute, Id = x.Id }).ToList(); hm.Categories = con.Categories.Select(x => x).ToList(); return(View(hm)); } if (CategoryId == 0 && GenderId == 3) { hm.Rows = con.Products.Select(x => new ProductListingVM.Row { Price = x.Price.ToString(), ProductName = x.ProductName, CategoryId = x.CategoryId, GenderId = x.GenderId, ShortDescription = x.ShortDescription, Route = x.ImageRoute, Id = x.Id }).ToList(); hm.Categories = con.Categories.Select(x => x).ToList(); return(View(hm)); } if (CategoryId == 0) { hm.Rows = con.Products.Where(x => x.GenderId == GenderId).Select(x => new ProductListingVM.Row { Price = x.Price.ToString(), ProductName = x.ProductName, CategoryId = x.CategoryId, GenderId = x.GenderId, ShortDescription = x.ShortDescription, Route = x.ImageRoute, Id = x.Id }).ToList(); hm.Categories = con.Categories.Select(x => x).ToList(); return(View(hm)); } hm.Rows = con.Products.Where(x => x.CategoryId == CategoryId).Select(x => new ProductListingVM.Row { Price = x.Price.ToString(), ProductName = x.ProductName, CategoryId = x.CategoryId, GenderId = x.GenderId, ShortDescription = x.ShortDescription, Route = x.ImageRoute, Id = x.Id }).ToList(); return(View(hm)); }
//search bar public IActionResult Search(HomePageIndexVM modelH = null, BrandListingVM modelB = null, ProductListingVM modelP = null) { string search = null; if (modelH.Search != null) { search = modelH.Search; } else if (modelB.Search != null) { search = modelB.Search; } else if (modelP.Search != null) { search = modelP.Search; } return(RedirectToAction("ProductListing", new { search = search })); }