using Microsoft.AspNetCore.Mvc; using Microsoft.eShopOnContainers.WebMVC.Models; using Microsoft.eShopOnContainers.WebMVC.Models.CartViewModels; using Microsoft.eShopOnContainers.WebMVC.Services; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.WebMVC.ViewComponents { public class Cart : ViewComponent { private readonly IBasketService _cartSvc; public Cart(IBasketService cartSvc) { _cartSvc = cartSvc; } public async Task InvokeAsync(ApplicationUser user) { var itemsInCart = await ItemsInCartAsync(user); var vm = new CartComponentViewModel() { ItemsCount = itemsInCart }; return View(vm); } private Task ItemsInCartAsync(ApplicationUser user) { _cartSvc.GetBasket(user); return Task.Run ( ()=> { return _cartSvc.ItemsInCart; }); } } }