Minor cleanup (#63)
This commit is contained in:
@@ -3,26 +3,26 @@ using System.Linq;
|
||||
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
public class Basket : BaseEntity
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
private readonly List<BasketItem> _items = new List<BasketItem>();
|
||||
public IEnumerable<BasketItem> Items => _items.ToList();
|
||||
public class Basket : BaseEntity
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
private readonly List<BasketItem> _items = new List<BasketItem>();
|
||||
public IReadOnlyCollection<BasketItem> Items => _items.AsReadOnly();
|
||||
|
||||
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1)
|
||||
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1)
|
||||
{
|
||||
if (!Items.Any(i => i.CatalogItemId == catalogItemId))
|
||||
{
|
||||
if (!Items.Any(i => i.CatalogItemId == catalogItemId))
|
||||
_items.Add(new BasketItem()
|
||||
{
|
||||
_items.Add(new BasketItem()
|
||||
{
|
||||
CatalogItemId = catalogItemId,
|
||||
Quantity = quantity,
|
||||
UnitPrice = unitPrice
|
||||
});
|
||||
return;
|
||||
}
|
||||
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId);
|
||||
existingItem.Quantity += quantity;
|
||||
CatalogItemId = catalogItemId,
|
||||
Quantity = quantity,
|
||||
UnitPrice = unitPrice
|
||||
});
|
||||
return;
|
||||
}
|
||||
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId);
|
||||
existingItem.Quantity += quantity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,15 +25,5 @@ namespace ApplicationCore.Entities.OrderAggregate
|
||||
Country = country;
|
||||
ZipCode = zipcode;
|
||||
}
|
||||
|
||||
//protected override IEnumerable<object> GetAtomicValues()
|
||||
//{
|
||||
// yield return Street;
|
||||
// yield return City;
|
||||
// yield return State;
|
||||
// yield return Country;
|
||||
// yield return ZipCode;
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace ApplicationCore.Entities.OrderAggregate
|
||||
// but only through the method Order.AddOrderItem() which includes behavior.
|
||||
private readonly List<OrderItem> _orderItems = new List<OrderItem>();
|
||||
|
||||
public IReadOnlyCollection<OrderItem> OrderItems => _orderItems;
|
||||
public IReadOnlyCollection<OrderItem> OrderItems => _orderItems.AsReadOnly();
|
||||
// Using List<>.AsReadOnly()
|
||||
// This will create a read only wrapper around the private list so is protected against "external updates".
|
||||
// It's much cheaper than .ToList() because it will not have to copy all items in a new collection. (Just one heap alloc for the wrapper instance)
|
||||
|
||||
Reference in New Issue
Block a user