public async Task <IActionResult> Index(string category) { IEnumerable <Pizza> pizzas; string currentCategory = string.Empty; if (string.IsNullOrEmpty(category)) { pizzas = await this._pizzaService.GetAllIncludedAsync(); currentCategory = "All pizzas"; } else { pizzas = await this._pizzaService.GetAllByCategoryAsync(category); currentCategory = category; } var viewModel = new PizzaIndexViewModel() { Items = this._mapper.Map <List <PizzaItemViewModel> >(pizzas), CurrentCategory = currentCategory }; return(View(viewModel)); }
public async Task <ActionResult> Index() { var pizzaResult = await PizzaService.GetGroupedPizzas(); var model = new PizzaIndexViewModel() { Result = pizzaResult?.Take(20).ToList(), TotalOrders = pizzaResult != null?pizzaResult.Sum(x => x.Count) : 0 }; return(View(model)); }