public async Task <IActionResult> LostItems(string sortOrder, string currentFilter, string searchString, int?pageNumber) { var lostitems = lostrepository.GetAllLostItems(); ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; ViewBag.Action = "LostItems"; if (searchString != null) { pageNumber = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var lostItems = lostrepository.GetFilterLostItems().Where(c => c.IsDeleted == false); if (!String.IsNullOrEmpty(searchString)) { lostItems = lostItems. Where(c => c.NameOfLostItem.Contains(searchString) || c.Description.Contains(searchString)); } switch (sortOrder) { case "name_desc": lostItems = lostItems.OrderByDescending(c => c.NameOfLostItem); break; case "Date": lostItems = lostItems.OrderBy(s => s.DateMisplaced); break; case "date_desc": lostItems = lostItems.OrderByDescending(c => c.DateMisplaced); break; default: lostItems = lostItems.OrderBy(c => c.NameOfLostItem); break; } int pageSize = 2; return(View(await PaginatedList <LostItem> .CreateAsync(lostItems.AsNoTracking(), pageNumber ?? 1, pageSize))); }
public async Task <IActionResult> GetLostItems() { IEnumerable <LostItem> lostItems = await repository.GetAllLostItems(); return(View(lostItems)); }