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:
7
src/ApplicationCore/CatalogSettings.cs
Normal file
7
src/ApplicationCore/CatalogSettings.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Microsoft.eShopWeb
|
||||
{
|
||||
public class CatalogSettings
|
||||
{
|
||||
public string CatalogBaseUrl { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,5 @@
|
||||
public CatalogType CatalogType { get; set; }
|
||||
public int CatalogBrandId { get; set; }
|
||||
public CatalogBrand CatalogBrand { get; set; }
|
||||
public CatalogItem() { }
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ namespace ApplicationCore.Interfaces
|
||||
Task<Basket> GetBasket(string basketId);
|
||||
Task<Basket> CreateBasket();
|
||||
Task<Basket> CreateBasketForUser(string userId);
|
||||
Task UpdateBasket(Basket basket);
|
||||
|
||||
Task AddItemToBasket(Basket basket, int productId, int quantity);
|
||||
//Task UpdateBasket(Basket basket);
|
||||
}
|
||||
}
|
||||
|
||||
8
src/ApplicationCore/Interfaces/IUriComposer.cs
Normal file
8
src/ApplicationCore/Interfaces/IUriComposer.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ApplicationCore.Interfaces
|
||||
{
|
||||
|
||||
public interface IUriComposer
|
||||
{
|
||||
string ComposePicUri(string uriTemplate);
|
||||
}
|
||||
}
|
||||
20
src/ApplicationCore/Services/UriComposer.cs
Normal file
20
src/ApplicationCore/Services/UriComposer.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using ApplicationCore.Interfaces;
|
||||
using Microsoft.eShopWeb;
|
||||
|
||||
namespace ApplicationCore.Services
|
||||
{
|
||||
public class UriComposer : IUriComposer
|
||||
{
|
||||
private readonly CatalogSettings _catalogSettings;
|
||||
|
||||
public UriComposer(CatalogSettings catalogSettings)
|
||||
{
|
||||
_catalogSettings = catalogSettings;
|
||||
}
|
||||
public string ComposePicUri(string uriTemplate)
|
||||
{
|
||||
return uriTemplate.Replace("http://catalogbaseurltobereplaced", _catalogSettings.CatalogBaseUrl);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user