// GET: public async Task <IActionResult> ListBars(string sortOrder, int?pageNumber) { try { var listVM = new ListBarsViewModel(); listVM.CurrentSortOrder = sortOrder; listVM.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; listVM.RatingSortParm = sortOrder == "Rating" ? "rating_asc" : "Rating"; var bars = await _barServices.GetAllBars(pageNumber, sortOrder); if (bars.Count == 0) { _toast.AddInfoToastMessage("There are no more cocktails!"); } var pagList = new PaginatedList <BarViewModel>() { PageIndex = bars.PageIndex, TotalPages = bars.TotalPages }; foreach (var item in bars) { pagList.Add(item.MapBarToVM()); } listVM.AllBars = pagList; if (bars.PageIndex == 1) { return(View(listVM)); } return(PartialView("_BarPaginationPartial", listVM)); } catch (Exception ex) { _toast.AddErrorToastMessage(ex.Message); ViewBag.ErrorTitle = ""; return(View("Error")); } }