Cart Updates (#26)

* ardalis/cart-updates

Updating how items are added to cart and displayed in cart.

* Cleaning up UI
This commit is contained in:
Steve Smith
2017-08-07 09:49:12 -04:00
committed by GitHub
parent b52048b74d
commit b67f8cc050
16 changed files with 258 additions and 22 deletions

View File

@@ -8,19 +8,20 @@ namespace Microsoft.eShopWeb.ApplicationCore.Entities
public string BuyerId { get; set; }
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
public void AddItem(int productId, decimal unitPrice, int quantity = 1)
public void AddItem(CatalogItem item, decimal unitPrice, int quantity = 1)
{
if(!Items.Any(i => i.ProductId == productId))
if(!Items.Any(i => i.Item.Id == item.Id))
{
Items.Add(new BasketItem()
{
ProductId = productId,
Item = item,
//ProductId = productId,
Quantity = quantity,
UnitPrice = unitPrice
});
return;
}
var existingItem = Items.FirstOrDefault(i => i.ProductId == productId);
var existingItem = Items.FirstOrDefault(i => i.Item.Id == item.Id);
existingItem.Quantity += quantity;
}
}

View File

@@ -2,8 +2,9 @@
{
public class BasketItem : BaseEntity<string>
{
public int ProductId { get; set; }
//public int ProductId { get; set; }
public decimal UnitPrice { get; set; }
public int Quantity { get; set; }
public CatalogItem Item { get; set; }
}
}

View File

@@ -10,6 +10,5 @@
public CatalogType CatalogType { get; set; }
public int CatalogBrandId { get; set; }
public CatalogBrand CatalogBrand { get; set; }
public CatalogItem() { }
}
}