Cleaning things up and getting add item to cart working for anonymous or authenticated users.
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace ApplicationCore.Entities
|
||||
{
|
||||
public class ApplicationUser : ClaimsIdentity
|
||||
{
|
||||
public string UserId { get; set; }
|
||||
public string UserName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.eShopWeb.ApplicationCore.Entities
|
||||
{
|
||||
@@ -6,5 +7,21 @@ 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
using ApplicationCore.Entities;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Security.Principal;
|
||||
using Microsoft.eShopWeb.ApplicationCore.Entities;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ApplicationCore.Interfaces
|
||||
{
|
||||
public interface IBasketService
|
||||
{
|
||||
Task<Basket> GetBasket(ApplicationUser user);
|
||||
}
|
||||
|
||||
public interface IIdentityParser<T>
|
||||
{
|
||||
T Parse(IPrincipal principal);
|
||||
Task<Basket> GetBasket(string basketId);
|
||||
Task<Basket> CreateBasket();
|
||||
Task<Basket> CreateBasketForUser(string userId);
|
||||
Task UpdateBasket(Basket basket);
|
||||
}
|
||||
}
|
||||
|
||||
9
src/ApplicationCore/Interfaces/IIdentityParser.cs
Normal file
9
src/ApplicationCore/Interfaces/IIdentityParser.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Security.Principal;
|
||||
|
||||
namespace ApplicationCore.Interfaces
|
||||
{
|
||||
public interface IIdentityParser<T>
|
||||
{
|
||||
T Parse(IPrincipal principal);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user