public ActionResult Index(string category, string search) { BlogpageModels blogpageModel = new BlogpageModels(); ViewBag.search = search; try { blogpageModel.Blogpage = _blogpageService.GetAll().Where(i => i.isApproved == true).FirstOrDefault(); if (!string.IsNullOrEmpty(category)) { blogpageModel.Blogs = _blogService.GetBlogsByCategory(category).Where(i => i.isPublished == true && i.BlogConfirm == true).ToList(); ViewBag.Category = category; } else { blogpageModel.Blogs = _blogService.GetAllWithCategory().Where(i => i.isPublished == true && i.BlogConfirm == true).OrderByDescending(d => d.BlogDate).ToList(); ViewBag.category = "All"; } if (!string.IsNullOrEmpty(search)) { blogpageModel.Blogs = _blogService.GetAllWithCategory().Where(i => i.isPublished == true).Where(i => EF.Functions.Like(i.BlogTitle, "%" + search + "%") || EF.Functions.Like(i.BlogContent, "%" + search + "%")).OrderByDescending(d => d.BlogDate).ToList(); } blogpageModel.Categories = _categoryService.GetAll().Where(i => i.CategoryType == "Blog" && i.isApproved == true).ToList(); } catch (Exception) { blogpageModel.Blogpage = null; } return(View(blogpageModel)); }
public IActionResult Index() { var model = _blogpageService.GetAll(); ViewBag.items = model.Where(i => i.isApproved == true).Count(); if (ViewBag.items == 1) { ViewBag.alert = false; } else { ViewBag.alert = true; } return(View(model)); }