2016-11-07 18:37:11 +01:00

37 lines
1.0 KiB
C#

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<IViewComponentResult> InvokeAsync(ApplicationUser user)
{
var itemsInCart = await ItemsInCartAsync(user);
var vm = new CartComponentViewModel()
{
ItemsCount = itemsInCart
};
return View(vm);
}
private Task<int> ItemsInCartAsync(ApplicationUser user)
{
_cartSvc.GetBasket(user);
return Task.Run ( ()=> { return _cartSvc.ItemsInCart; });
}
}
}