public async Task <IActionResult> Index(int id = 1) { var listOfIngredients = new IngredientsListViewModel(); listOfIngredients.Paging.Count = await ingredientServices.AllIngredientsCountAsync(); listOfIngredients.Paging.ItemsPerPage = itemsPerPage; listOfIngredients.Paging.CurrentPage = id; listOfIngredients.Ingredients = (await ingredientServices.GetAllPagedDTOAsync(listOfIngredients.Paging.ItemsPerPage, listOfIngredients.Paging.CurrentPage)) .Select(c => c.MapToViewModel()); return(View(listOfIngredients)); }
public async Task <IActionResult> All(int id = 1) { var itemsPerPage = 15; var ingredients = await this.ingredientsService.GetAllAsync <IngredientViewModel>(); var viewModel = new IngredientsListViewModel { Ingredients = ingredients .Skip((id - 1) * itemsPerPage) .Take(itemsPerPage), CurrentPage = id, ItemsCount = ingredients.Count(), ItemsPerPage = itemsPerPage, }; this.ViewData["Action"] = nameof(this.All); return(this.View(viewModel)); }
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")); } }
public async Task <IActionResult> GetTenIngredients(int?currPage) { try { var currentPage = currPage ?? 1; var totalPages = await this.ingredientService.GetPageCountAsync(10); var tenIngredients = await this.ingredientService.GetTenIngredientsOrderedByNameAsync(currentPage); var mappedTenIngredients = this.ingredientViewModelMapper.MapFrom(tenIngredients); var model = new IngredientsListViewModel() { CurrPage = currentPage, TotalPages = totalPages, TenIngredients = mappedTenIngredients, }; if (totalPages > currentPage) { model.NextPage = currentPage + 1; } if (currentPage > 1) { model.PrevPage = currentPage - 1; } return(PartialView("_IngredientsIndexTable", model)); } catch (Exception) { this.toastNotification.AddWarningToastMessage("Something went wrong, please try again"); return(RedirectToAction(nameof(Index))); } }