Basket persistence (#41)
* Renamed Cart to Basket throughout * Implemented cookie-based anonymous basket handling and transfer to user upon login. Still need to implement transfer upon registration.
This commit is contained in:
@@ -6,13 +6,14 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
public class Basket : BaseEntity
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
|
||||
private readonly List<BasketItem> _items = new List<BasketItem>();
|
||||
public IEnumerable<BasketItem> Items => _items.ToList();
|
||||
|
||||
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1)
|
||||
{
|
||||
if (!Items.Any(i => i.CatalogItemId == catalogItemId))
|
||||
{
|
||||
Items.Add(new BasketItem()
|
||||
_items.Add(new BasketItem()
|
||||
{
|
||||
CatalogItemId = catalogItemId,
|
||||
Quantity = quantity,
|
||||
|
||||
@@ -13,10 +13,18 @@ namespace ApplicationCore.Specifications
|
||||
BasketId = basketId;
|
||||
AddInclude(b => b.Items);
|
||||
}
|
||||
public BasketWithItemsSpecification(string buyerId)
|
||||
{
|
||||
BuyerId = buyerId;
|
||||
AddInclude(b => b.Items);
|
||||
}
|
||||
|
||||
public int BasketId { get; }
|
||||
public int? BasketId { get; }
|
||||
public string BuyerId { get; }
|
||||
|
||||
public Expression<Func<Basket, bool>> Criteria => b => b.Id == BasketId;
|
||||
public Expression<Func<Basket, bool>> Criteria => b =>
|
||||
(BasketId.HasValue && b.Id == BasketId.Value)
|
||||
|| (BuyerId != null && b.BuyerId == BuyerId);
|
||||
|
||||
public List<Expression<Func<Basket, object>>> Includes { get; } = new List<Expression<Func<Basket, object>>>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user