public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page) { int count = 0; int pageSize = 10; int pageNumber = (page ?? 1); ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "donorID_desc" : ""; ViewBag.CompanySortParm = String.IsNullOrEmpty(sortOrder) ? "company" : ""; ViewBag.CompanySortParmDesc = String.IsNullOrEmpty(sortOrder) ? "company_desc" : ""; ViewBag.EmailSortParm = String.IsNullOrEmpty(sortOrder) ? "email" : ""; ViewBag.EmailSortParmDesc = String.IsNullOrEmpty(sortOrder) ? "email_desc" : ""; ViewBag.AddressSortParm = String.IsNullOrEmpty(sortOrder) ? "address" : ""; ViewBag.AddressSortParmDesc = String.IsNullOrEmpty(sortOrder) ? "address_desc" : ""; //ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; IEnumerable <DONOR> donor = new List <DONOR>(); if (searchString != null) { page = 1; donor = drRepo.FindBy(searchString); } else { searchString = currentFilter; donor = drRepo.GetDonors; } ViewBag.CurrentFilter = searchString; //used to remove features for non-admin users. string userId = User.Identity.GetUserId(); var user = data.AspNetUsers.FirstOrDefault(p => p.Id == userId); ViewBag.role = user.NewRole; //count = drRepo.GetDonors.Count(); count = donor.Count(); ViewBag.Count = count; switch (sortOrder) { case "donorID_desc": donor = donor.OrderByDescending(d => d.FName); break; case "email_desc": donor = donor.OrderByDescending(d => d.Email); break; case "email": donor = donor.OrderBy(d => d.Email); break; case "company_desc": donor = donor.OrderByDescending(d => d.CompanyName); break; case "company": donor = donor.OrderBy(d => d.CompanyName); break; case "address_desc": donor = donor.OrderByDescending(d => d.Address); break; case "address": donor = donor.OrderBy(d => d.Address); break; default: donor = donor.OrderBy(d => d.LName); break; } DonorViewModel DonorList = new DonorViewModel { Donors = donor.Take(count).ToPagedList(pageNumber, pageSize) }; return(View(DonorList)); }