Ardalis/upgrade1 (#44)

* Upgrading to netcore 2.0
Updating repository to support async options and refactoring to use it.

* Starting work on tracking customer orders feature.

* Cleaning up some bugs
Working on basket view component implementation

* Fixing up styles, especially for basket in header.
This commit is contained in:
Steve Smith
2017-08-28 12:15:18 -04:00
committed by GitHub
parent 19c10ed0e5
commit ed5d17672d
45 changed files with 1024 additions and 482 deletions

View File

@@ -0,0 +1,27 @@
using ApplicationCore.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopWeb.ViewModels;
using System.Threading.Tasks;
namespace Web.ViewComponents
{
public class Basket : ViewComponent
{
private readonly IBasketService _cartSvc;
public Basket(IBasketService cartSvc) => _cartSvc = cartSvc;
public async Task<IViewComponentResult> InvokeAsync(string userName)
{
var vm = new BasketComponentViewModel();
var itemsInCart = await ItemsInBasketAsync(userName);
vm.ItemsCount = itemsInCart;
return View(vm);
}
private async Task<int> ItemsInBasketAsync(string userName)
{
var basket = await _cartSvc.GetOrCreateBasketForUser(userName);
return basket.Items.Count;
}
}
}