Adding cart/basket support and applicationuser (without EF requirement)
This commit is contained in:
53
src/Web/Controllers/CartController.cs
Normal file
53
src/Web/Controllers/CartController.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Microsoft.eShopWeb.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
using ApplicationCore.Interfaces;
|
||||
using ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopWeb.Controllers
|
||||
{
|
||||
public class CartController : Controller
|
||||
{
|
||||
private readonly ICatalogService _catalogSvc;
|
||||
private readonly IBasketService _basketSvc;
|
||||
private readonly IIdentityParser<ApplicationUser> _appUserParser;
|
||||
|
||||
public CartController(IBasketService basketSvc,
|
||||
IIdentityParser<ApplicationUser> appUserParser)
|
||||
{
|
||||
//_catalogSvc = catalogSvc;
|
||||
_basketSvc = basketSvc;
|
||||
_appUserParser = appUserParser;
|
||||
}
|
||||
|
||||
|
||||
// GET: /<controller>/
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var user = _appUserParser.Parse(HttpContext.User);
|
||||
var viewmodel = await _basketSvc.GetBasket(user);
|
||||
|
||||
return View(viewmodel);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> AddToCart(CatalogItem productDetails)
|
||||
{
|
||||
if (productDetails.Id != null)
|
||||
{
|
||||
var user = _appUserParser.Parse(HttpContext.User);
|
||||
var product = new BasketItem()
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
Quantity = 1,
|
||||
UnitPrice = productDetails.Price,
|
||||
ProductId = productDetails.Id
|
||||
};
|
||||
//await _basketSvc.AddItemToBasket(user, product);
|
||||
}
|
||||
return RedirectToAction("Index", "Catalog");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user