Example #1
0
 public ActionResult Search(string search)
 {
     if (search != null)
     {
         ViewBag.Search = search;
         search         = search.ToLower().Trim();
         var products = pr.SelectAll().Where(i => i.Name.ToLower().Contains(search) || i.Brand.ToLower().Contains(search) || i.Model.ToLower().Contains(search) || i.Code.ToLower() == search).ToList();
         foreach (var mainCategory in mcr.SelectAll().Where(i => i.Name.ToLower().Contains(search)).ToList())
         {
             foreach (var subCategory in mainCategory.SubCategories)
             {
                 products.AddRange(subCategory.Products);
             }
         }
         foreach (var subCategory1 in scr.SelectAll().Where(i => i.Name.ToLower().Contains(search)).ToList())
         {
             products.AddRange(subCategory1.Products);
         }
         products = products.Distinct().ToList();
         return(View(products));
     }
     return(View("Index"));
 }