Пример #1
0
        public async Task <IActionResult> Index(int?currPage)
        {
            try
            {
                currPage = currPage ?? 1;

                var tenIngredientsDtos = await _ingredientServices
                                         .GetTenIngredientsAsync((int)currPage);

                var totalPages = await _ingredientServices
                                 .GetPageCountForIngredientsAsync(10);

                var tenIngredientsVm = tenIngredientsDtos
                                       .Select(c => c.MapToViewModel()).ToList();

                var litingViewModel = new IngredientsListViewModel()
                {
                    TenIngredientsList = tenIngredientsVm,
                    CurrPage           = (int)currPage,
                    TotalPages         = totalPages,
                    MoreToLoad         = true
                };

                if (tenIngredientsDtos.Count == 0)
                {
                    _toast.AddInfoToastMessage("There are no more ingredients!");
                    litingViewModel.MoreToLoad = false;
                }
                if (currPage == 1)
                {
                    return(View(litingViewModel));
                }

                return(PartialView("_LoadMorePartial", litingViewModel));
            }
            catch (Exception ex)
            {
                _toast.AddErrorToastMessage(ex.Message);
                ViewBag.ErrorTitle = "";
                return(View("Error"));
            }
        }