diff --git a/src/ApplicationCore/ApplicationCore.csproj b/src/ApplicationCore/ApplicationCore.csproj index 74295a0..35fa64f 100644 --- a/src/ApplicationCore/ApplicationCore.csproj +++ b/src/ApplicationCore/ApplicationCore.csproj @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/src/ApplicationCore/Entities/ApplicationUser.cs b/src/ApplicationCore/Entities/ApplicationUser.cs new file mode 100644 index 0000000..ee361c5 --- /dev/null +++ b/src/ApplicationCore/Entities/ApplicationUser.cs @@ -0,0 +1,10 @@ +using System.Security.Claims; + +namespace ApplicationCore.Entities +{ + public class ApplicationUser : ClaimsIdentity + { + public string UserId { get; set; } + public string UserName { get; set; } + } +} diff --git a/src/ApplicationCore/Entities/BaseEntity.cs b/src/ApplicationCore/Entities/BaseEntity.cs index b021b65..fdc1cf7 100644 --- a/src/ApplicationCore/Entities/BaseEntity.cs +++ b/src/ApplicationCore/Entities/BaseEntity.cs @@ -1,7 +1,7 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities { - public class BaseEntity + public class BaseEntity { - public int Id { get; set; } + public T Id { get; set; } } } diff --git a/src/ApplicationCore/Entities/Basket.cs b/src/ApplicationCore/Entities/Basket.cs new file mode 100644 index 0000000..1fc989a --- /dev/null +++ b/src/ApplicationCore/Entities/Basket.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; + +namespace Microsoft.eShopWeb.ApplicationCore.Entities +{ + public class Basket : BaseEntity + { + public string BuyerId { get; set; } + public List Items { get; set; } = new List(); + } +} diff --git a/src/ApplicationCore/Entities/BasketItem.cs b/src/ApplicationCore/Entities/BasketItem.cs new file mode 100644 index 0000000..19d02fd --- /dev/null +++ b/src/ApplicationCore/Entities/BasketItem.cs @@ -0,0 +1,9 @@ +namespace Microsoft.eShopWeb.ApplicationCore.Entities +{ + public class BasketItem : BaseEntity + { + public int ProductId { get; set; } + public decimal UnitPrice { get; set; } + public int Quantity { get; set; } + } +} diff --git a/src/ApplicationCore/Entities/CatalogBrand.cs b/src/ApplicationCore/Entities/CatalogBrand.cs index 1c90dfa..5c1e493 100644 --- a/src/ApplicationCore/Entities/CatalogBrand.cs +++ b/src/ApplicationCore/Entities/CatalogBrand.cs @@ -1,6 +1,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities { - public class CatalogBrand : BaseEntity + public class CatalogBrand : BaseEntity { public string Brand { get; set; } } diff --git a/src/ApplicationCore/Entities/CatalogItem.cs b/src/ApplicationCore/Entities/CatalogItem.cs index d0ca18e..9f3bdaf 100644 --- a/src/ApplicationCore/Entities/CatalogItem.cs +++ b/src/ApplicationCore/Entities/CatalogItem.cs @@ -1,6 +1,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities { - public class CatalogItem : BaseEntity + public class CatalogItem : BaseEntity { public string Name { get; set; } public string Description { get; set; } diff --git a/src/ApplicationCore/Entities/CatalogType.cs b/src/ApplicationCore/Entities/CatalogType.cs index d1982a6..c6cbcc5 100644 --- a/src/ApplicationCore/Entities/CatalogType.cs +++ b/src/ApplicationCore/Entities/CatalogType.cs @@ -1,6 +1,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities { - public class CatalogType : BaseEntity + public class CatalogType : BaseEntity { public string Type { get; set; } } diff --git a/src/ApplicationCore/Interfaces/IBasketService.cs b/src/ApplicationCore/Interfaces/IBasketService.cs new file mode 100644 index 0000000..1b868a1 --- /dev/null +++ b/src/ApplicationCore/Interfaces/IBasketService.cs @@ -0,0 +1,18 @@ +using ApplicationCore.Entities; +using Microsoft.eShopWeb.ApplicationCore.Entities; +using System.Security.Principal; +using System.Threading.Tasks; + +namespace ApplicationCore.Interfaces +{ + public interface IBasketService + { + Task GetBasket(ApplicationUser user); + } + + public interface IIdentityParser + { + T Parse(IPrincipal principal); + } + +} diff --git a/src/Web/Controllers/CartController.cs b/src/Web/Controllers/CartController.cs new file mode 100644 index 0000000..70613dd --- /dev/null +++ b/src/Web/Controllers/CartController.cs @@ -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 _appUserParser; + + public CartController(IBasketService basketSvc, + IIdentityParser appUserParser) + { + //_catalogSvc = catalogSvc; + _basketSvc = basketSvc; + _appUserParser = appUserParser; + } + + + // GET: // + public async Task Index() + { + var user = _appUserParser.Parse(HttpContext.User); + var viewmodel = await _basketSvc.GetBasket(user); + + return View(viewmodel); + } + + public async Task 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"); + } + + } +} diff --git a/src/Web/Program.cs b/src/Web/Program.cs index c02012b..10565bd 100644 --- a/src/Web/Program.cs +++ b/src/Web/Program.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; +using System.IO; using Microsoft.AspNetCore.Hosting; namespace Microsoft.eShopWeb