建立Model
DbContext
建立Repository、IRepository。
修改UnitOfWOrk、IUnitOfWork。
Area新增Cart與wwwroot新增js
_Layout修正
建立ShoppingCart Model
public class ShoppingCart
{
public int Id { get; set; }
public int ProductId { get; set; }
[ForeignKey("ProductId")]
[ValidateNever]
public Product Product { get; set; }
[Range(1, 100, ErrorMessage = "請輸入1-100的數字")]
public int Count { get; set; }
public string Color { get; set; }
public string Size { get; set; }
public string ApplicationUserId { get; set; }
[ForeignKey("ApplicationUserId")]
[ValidateNever]
public ApplicationUser ApplicationUser { get; set; }
}
public DbSet<ShoppingCart> ShoppingCarts { get; set; }
Add-migration addShoppingCartTbl
Update-database
public IShoppingCartRepository ShoppingCart { get; private set; }
ShoppingCart = new ShoppingCartRepository(_db);
IShoppingCartRepository ShoppingCart { get; }