public ActionResult SearchBlog(VmSearch search) { if (search.SearchText != null) { if (search.Page == "Blog") { List <Blog> blogs = new List <Blog>(); blogs = db.Blog.Include("Images") .Include("Tags") .Include("Comments") .Where(a => a.Title.Contains(search.SearchText)).ToList(); TempData["data"] = blogs; return(RedirectToAction("Blog")); } else if (search.Page == "Product") { List <Product> products = new List <Product>(); products = db.Product.Include("productInfos") .Include("productInfos.Images") .Where(a => a.Name.Contains(search.SearchText)).ToList(); TempData["data"] = products; return(RedirectToAction("AllResult")); } } return(View()); }
//Home/FullSearch public ActionResult Search(string searchText) { VmSearch model = new VmSearch(); model.Courses = model.Courses = db.Courses.Where(w => (!string.IsNullOrEmpty(searchText) ? w.Title.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.CkEditorContent.Contains(searchText) : true)).ToList(); model.Events = db.Events.Include("Category").Where(w => (!string.IsNullOrEmpty(searchText) ? w.Name.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Venue.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Content.Contains(searchText) : true)).ToList(); model.Teachers = db.Teachers.Include("Position").Include("SocialTeachers").Where(w => (!string.IsNullOrEmpty(searchText) ? w.Fullname.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Content.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Degree.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Experience.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Faculty.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Hobbies.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Skype.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Email.Contains(searchText) : true)).ToList(); model.Blogs = db.Blogs.Include("Category").Include("User").Where(w => (!string.IsNullOrEmpty(searchText) ? w.Title.Contains(searchText) : true) || (!string.IsNullOrEmpty(searchText) ? w.Content.Contains(searchText) : true)).ToList(); return(View(model)); }