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:
@@ -1,7 +1,7 @@
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
public class BaseEntity<T>
|
||||
public class BaseEntity
|
||||
{
|
||||
public T Id { get; set; }
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
public class BasketItem : BaseEntity<string>
|
||||
public class BasketItem : BaseEntity
|
||||
{
|
||||
//public int ProductId { get; set; }
|
||||
public decimal UnitPrice { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
public CatalogItem Item { get; set; }
|
||||
public int CatalogItemId { get; set; }
|
||||
// public CatalogItem Item { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
public class CatalogBrand : BaseEntity<int>
|
||||
public class CatalogBrand : BaseEntity
|
||||
{
|
||||
public string Brand { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
public class CatalogItem : BaseEntity<int>
|
||||
public class CatalogItem : BaseEntity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
public class CatalogType : BaseEntity<int>
|
||||
public class CatalogType : BaseEntity
|
||||
{
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user