Refactoring and Adding Tests (#28)
* Introducing repository and refactoring services. Changing entities to use int keys everywhere. * Refactoring application services to live in web project and only reference repositories, not EF contexts. * Cleaning up implementations * Moving logic out of CatalogController Moving entity knowledge out of viewmodels. * Implementing specification includes better for catalogservice * Cleaning up and adding specification unit tests
This commit is contained in:
@@ -3,25 +3,24 @@ using System.Linq;
|
||||
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
public class Basket : BaseEntity<string>
|
||||
public class Basket : BaseEntity
|
||||
{
|
||||
public string BuyerId { get; set; }
|
||||
public List<BasketItem> Items { get; set; } = new List<BasketItem>();
|
||||
|
||||
public void AddItem(CatalogItem item, decimal unitPrice, int quantity = 1)
|
||||
public void AddItem(int catalogItemId, decimal unitPrice, int quantity = 1)
|
||||
{
|
||||
if(!Items.Any(i => i.Item.Id == item.Id))
|
||||
if (!Items.Any(i => i.CatalogItemId == catalogItemId))
|
||||
{
|
||||
Items.Add(new BasketItem()
|
||||
{
|
||||
Item = item,
|
||||
//ProductId = productId,
|
||||
CatalogItemId = catalogItemId,
|
||||
Quantity = quantity,
|
||||
UnitPrice = unitPrice
|
||||
});
|
||||
return;
|
||||
}
|
||||
var existingItem = Items.FirstOrDefault(i => i.Item.Id == item.Id);
|
||||
var existingItem = Items.FirstOrDefault(i => i.CatalogItemId == catalogItemId);
|
||||
existingItem.Quantity += quantity;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user