public IActionResult Index(int id = 1, string name = "") { int count = SourceManager.GetCount(name); int prev = id - 1; int next = id + 1; if (id <= 1) { prev = 1; } if (count <= id * 5) { next = id; } ViewBag.Title = "Home"; ViewBag.Name = name; ViewBag.Prev = prev; ViewBag.Next = next; ViewBag.ID = id; return(View(SourceManager.Get(id, 5, name))); }
public ActionResult Table(int page = 1, string filter = "") { SourceManager manager = new SourceManager(); ViewBag.Filter = filter; TempData["CurrentPage"] = page; TempData["PageCount"] = ((manager.GetCount() - 1) / _rowsPerPage) + 1; if (filter != "") { TempData["CurrentPage"] = page; TempData["PageCount"] = ((manager.GetCount(filter) - 1) / _rowsPerPage) + 1; var lista = manager.Get((page - 1) * _rowsPerPage, _rowsPerPage, filter); return(PartialView(lista)); } return(PartialView(manager.Get((page - 1) * _rowsPerPage, _rowsPerPage))); }
public IActionResult Index(int id = 1, string searchText = null) { // Pobranie ogólnej liczby osób int count = string.IsNullOrWhiteSpace(searchText) ? SourceManager.GetCount() : SourceManager.GetCount(searchText); // Przypisanie szukanego tekstu do ViewBag-a ViewBag.SearchText = searchText; // Dla mniej niż 10 osób - tylko 1 strona if (id <= 1 && (id * 10) >= count) { ViewBag.Previous = null; ViewBag.PreviousDis = "disabled"; ViewBag.Next = null; ViewBag.NextDis = "disabled"; ViewBag.Page = 1; } // Dla pierwszej strony else if (id <= 1) { ViewBag.Previous = null; ViewBag.PreviousDis = "disabled"; ViewBag.Next = 2; ViewBag.NextDis = ""; ViewBag.Page = id; } // Dla ostatniej strony else if ((id * 10) >= count) { ViewBag.Previous = id - 1; ViewBag.PreviousDis = ""; ViewBag.Next = null; ViewBag.NextDis = "disabled"; ViewBag.Page = id; } // Dla strony pomiędzy else { ViewBag.Previous = id - 1; ViewBag.PreviousDis = ""; ViewBag.Next = id + 1; ViewBag.NextDis = ""; ViewBag.Page = id; } // Zwrócenie modelu z listą osób List <PersonModel> list = string.IsNullOrWhiteSpace(searchText) ? SourceManager.Get(id, 10) : SourceManager.Get(id, 10, searchText); // Zwrócenie widoku return(View(list)); }