public ActionResult Index(string currentFilter, string searchString, int?page) { ViewBag.Categories = categoryHelper.GetAll().Where(cat => cat.isActive); if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var posts = from p in postHelper.GetAll().Where(post => post.isActive).OrderByDescending(p => p.DateCreated).ToList() select p; if (!string.IsNullOrEmpty(searchString)) { posts = posts.Where(p => p.Title.ToLower().Contains(searchString.ToLower())); } int pageSize = 16; int pageNumber = (page ?? 1); return(View(posts.ToPagedList(pageNumber, pageSize))); }
public ActionResult Index() { if (!LoggedIn()) { return(RedirectToAction("Login", "Auth")); } if (isAdmin()) { return(RedirectToAction("Index", "Admin")); } if (!isAdmin() && !isAuthor()) { return(RedirectToAction("Logout", "Auth")); } Author author = authorHelper.GetById(GetAuthorId()); if (!author.isEmailConfirmed) { return(RedirectToAction("ConfirmEmail")); } List <Post> posts = postHelper.GetAll().Where(p => p.AuthorId == author.Id && p.isActive).OrderByDescending(p => p.DateCreated).ToList(); ViewBag.Categories = categoryHelper.GetAll().Where(cat => cat.isActive); return(View(posts)); }
public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page) { if (!LoggedIn()) { return(RedirectToAction("LoginAdmin", "Auth")); } if (!isAdmin()) { return(RedirectToAction("Index", "Author")); } ViewBag.CurrentSort = sortOrder; ViewBag.TitleSortParm = string.IsNullOrEmpty(sortOrder) ? "title_desc" : ""; ViewBag.StatusSortParm = sortOrder == "Status" ? "status_desc" : "Status"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var posts = from p in postHelper.GetAll() select p; if (!string.IsNullOrEmpty(searchString)) { posts = posts.Where(p => p.Title.ToLower().Contains(searchString.ToLower())); } switch (sortOrder) { case "title_desc": posts = posts.OrderByDescending(p => p.Title); break; case "Status": posts = posts.OrderBy(p => p.isActive); break; case "status_desc": posts = posts.OrderByDescending(p => p.isActive); break; default: posts = posts.OrderBy(p => p.Title); break; } int pageSize = 10; int pageNumber = (page ?? 1); return(View(posts.ToPagedList(pageNumber, pageSize))); }