Sample ASP.NET Core 6.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

27 lines
843 B

using System.Collections.Generic;
using System.Linq;
namespace Microsoft.eShopWeb.ApplicationCore.Entities
{
public class Basket : BaseEntity<string>
{
public string BuyerId { get; set; }
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
public void AddItem(int productId, decimal unitPrice, int quantity = 1)
{
if(!Items.Any(i => i.ProductId == productId))
{
Items.Add(new BasketItem()
{
ProductId = productId,
Quantity = quantity,
UnitPrice = unitPrice
});
return;
}
var existingItem = Items.FirstOrDefault(i => i.ProductId == productId);
existingItem.Quantity += quantity;
}
}
}