// GET: Contact public ViewResult List(string city = null, string function = null, int items = 3, int page = 1) { ContactListViewModel model = new ContactListViewModel { Contacts = repository.Contacts .Where(c => city == null || c.City == city).Where(c => function == null || c.Function == function) .OrderBy(c => c.ContactId).Skip((page - 1) * items).Take(items), PagingInfo = new PagingInfo { CurrenPage = page, ItemsPerPage = items, TotalItems = (city == null & function == null) ? repository.Contacts.Count() : repository.Contacts.Where(e => city == null || e.City == city).Count(e => function == null || e.Function == function) }, CurrentCity = city, CurrentFunction = function }; if (city == null & function == null) { return View(model); } else return View("ListByCityOrFunction", model); }
public ActionResult ListByName(string lastName) { ContactListViewModel model = new ContactListViewModel { Contacts = repository.Contacts .Where(c => lastName == null || c.LastName == lastName).OrderBy(c => c.LastName), PagingInfo = new PagingInfo { CurrenPage = 1, ItemsPerPage = 3, TotalItems = repository.Contacts.Where(e => lastName == null || e.LastName == lastName).Count() }, CurrentCity = null, CurrentFunction = null }; if (lastName != "") { return View(model); } else { return RedirectToAction("FindByLastName", "Menu"); } }