public async Task <IActionResult> ListCocktails(string sortOrder, int?currPage, string orderByModel) { if (orderByModel == null) { ViewData["CurrentSort"] = sortOrder; //care ViewData["NameSortCriteria"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewData["RatingSortCriteria"] = sortOrder == "rating" ? "rating_desc" : "rating"; } else { sortOrder = orderByModel; } //there is some logic for the traditional page-numbers pagination (DONT remove it for now) try { currPage = currPage ?? 1; var fiveSortedCocktailsDtos = await _cocktailServices .GetFiveSortedCocktailsAsync(sortOrder, (int)currPage); var totalPages = await _cocktailServices .GetPageCountForCocktials(5); var fiveSortedCocktailsVm = fiveSortedCocktailsDtos .Select(c => c.MapToCocktailViewModel()).ToList(); var litingViewModel = new CocktailsListingViewModel() { FiveCocktailsList = fiveSortedCocktailsVm, CurrPage = (int)currPage, TotalPages = totalPages, SortOrder = sortOrder, MoreToLoad = true }; if (fiveSortedCocktailsDtos.Count == 0) { _toast.AddInfoToastMessage("There are no more cocktails!"); litingViewModel.MoreToLoad = false; //here i have to stop the request... return smthg.. } if (totalPages > currPage) { litingViewModel.NextPage = currPage + 1; } if (currPage > 1) { litingViewModel.PrevPage = currPage - 1; } // To add timeSpan and animation ! if (currPage == 1) { return(View("CocktailsGrid", litingViewModel)); } return(PartialView("_LoadMorePartial", litingViewModel)); //return View(allCocktailsVms.ToList()); } catch (Exception ex) { _toast.AddErrorToastMessage(ex.Message); ViewBag.ErrorTitle = ""; return(View("Error")); } }