|
|
@ -1,43 +1,36 @@ |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using ApplicationCore.Interfaces; |
|
|
using ApplicationCore.Interfaces; |
|
|
using Microsoft.eShopWeb.ApplicationCore.Entities; |
|
|
|
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.eShopWeb.ViewModels; |
|
|
using Microsoft.eShopWeb.ViewModels; |
|
|
using System.Linq; |
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.eShopWeb.Controllers |
|
|
namespace Microsoft.eShopWeb.Controllers |
|
|
{ |
|
|
{ |
|
|
|
|
|
[Route("[controller]/[action]")]
|
|
|
public class CartController : Controller |
|
|
public class CartController : Controller |
|
|
{ |
|
|
{ |
|
|
private readonly IBasketService _basketService; |
|
|
private readonly IBasketService _basketService; |
|
|
//private readonly IIdentityParser<ApplicationUser> _appUserParser;
|
|
|
|
|
|
private const string _basketSessionKey = "basketId"; |
|
|
private const string _basketSessionKey = "basketId"; |
|
|
private readonly IUriComposer _uriComposer; |
|
|
private readonly IUriComposer _uriComposer; |
|
|
|
|
|
|
|
|
public CartController(IBasketService basketService, |
|
|
public CartController(IBasketService basketService, |
|
|
IUriComposer uriComposer) |
|
|
IUriComposer uriComposer) |
|
|
// IIdentityParser<ApplicationUser> appUserParser)
|
|
|
|
|
|
{ |
|
|
{ |
|
|
_basketService = basketService; |
|
|
_basketService = basketService; |
|
|
_uriComposer = uriComposer; |
|
|
_uriComposer = uriComposer; |
|
|
// _appUserParser = appUserParser;
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
// GET: /<controller>/
|
|
|
|
|
|
public async Task<IActionResult> Index() |
|
|
public async Task<IActionResult> Index() |
|
|
{ |
|
|
{ |
|
|
//var user = _appUserParser.Parse(HttpContext.User);
|
|
|
|
|
|
var basketModel = await GetBasketFromSessionAsync(); |
|
|
var basketModel = await GetBasketFromSessionAsync(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return View(basketModel); |
|
|
return View(basketModel); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// GET: /Cart/AddToCart
|
|
|
// POST: /Cart/AddToCart
|
|
|
// TODO: This should be a POST.
|
|
|
[HttpPost] |
|
|
public async Task<IActionResult> AddToCart(CatalogItem productDetails) |
|
|
public async Task<IActionResult> AddToCart(CatalogItemViewModel productDetails) |
|
|
{ |
|
|
{ |
|
|
if (productDetails?.Id == null) |
|
|
if (productDetails?.Id == null) |
|
|
{ |
|
|
{ |
|
|
@ -50,6 +43,16 @@ namespace Microsoft.eShopWeb.Controllers |
|
|
return RedirectToAction("Index"); |
|
|
return RedirectToAction("Index"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
|
public async Task<IActionResult> Checkout() |
|
|
|
|
|
{ |
|
|
|
|
|
var basket = await GetBasketFromSessionAsync(); |
|
|
|
|
|
|
|
|
|
|
|
await _basketService.Checkout(basket.Id); |
|
|
|
|
|
|
|
|
|
|
|
return View("Checkout"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async Task<BasketViewModel> GetBasketFromSessionAsync() |
|
|
private async Task<BasketViewModel> GetBasketFromSessionAsync() |
|
|
{ |
|
|
{ |
|
|
string basketId = HttpContext.Session.GetString(_basketSessionKey); |
|
|
string basketId = HttpContext.Session.GetString(_basketSessionKey); |
|
|
|