public ActionResult SearchResult(string searchString) { if (Session["UserID"] != null) { ViewBag.IsLoggedIn = "True"; } if (String.IsNullOrEmpty(searchString)) { return(View());//TODO } try { ProductSearchResultDTO newProductsSearchResultDTO = new ProductSearchResultDTO(); ProductsSearchViewModel viewModel = new ProductsSearchViewModel(); newProductsSearchResultDTO = productDetailContext.GetProductwithString(searchString); if (newProductsSearchResultDTO.Products.Count() == 0) { return(View("NoSearch")); } viewModel = ProductsSearchResultVMMapper.Map <ProductSearchResultDTO, ProductsSearchViewModel>(newProductsSearchResultDTO); ViewBag.searchString = searchString; return(View(viewModel)); } catch (Exception ex) { ModelState.AddModelError("", ex + ":Exception occured"); } return(View()); }
//search product with the name or description public ProductSearchResultDTO GetProductwithString(string searchString) { try { ProductSearchResultDTO produDetailDTO = ProductDBObject.GetProductSearch(searchString); return(produDetailDTO); } catch (Exception ex) { throw new Exception("Unknown Error"); } }
//search the product using the name or description of the product public ProductSearchResultDTO GetProductSearch(string searchString) { ProductSearchResultDTO newProductsSearchResultDTO = new ProductSearchResultDTO(); dbContext.Database.Log = s => System.Diagnostics.Debug.WriteLine(s); newProductsSearchResultDTO.Products = (from pi in dbContext.Product.Where(p => p.Name.Contains(searchString) || p.Description.Contains(searchString)) join v in dbContext.Variant on pi.ID equals v.ProductID join img in dbContext.VariantImage on v.ID equals img.VariantID select new ProductDetailDTO() { ImageURL = img.ImageURL, Name = pi.Name, Description = pi.Description }).ToList(); return(newProductsSearchResultDTO); }