diff --git a/Client/Pages/Cart/Cart.razor b/Client/Pages/Cart/Cart.razor
new file mode 100644
index 0000000..f4b2d89
--- /dev/null
+++ b/Client/Pages/Cart/Cart.razor
@@ -0,0 +1,5 @@
+@page "/cart"
+
+
Your Shopping Cart
+
+
\ No newline at end of file
diff --git a/Client/Pages/Cart/Item.razor b/Client/Pages/Cart/Item.razor
new file mode 100644
index 0000000..b65c3e3
--- /dev/null
+++ b/Client/Pages/Cart/Item.razor
@@ -0,0 +1,13 @@
+
\ No newline at end of file
diff --git a/Client/ShoppingCartStarter.Client.csproj b/Client/ShoppingCartStarter.Client.csproj
index dad7fb9..e304ab2 100644
--- a/Client/ShoppingCartStarter.Client.csproj
+++ b/Client/ShoppingCartStarter.Client.csproj
@@ -16,4 +16,17 @@
+
+
+ true
+ PreserveNewest
+
+
+ true
+
+
+ true
+
+
+
diff --git a/Client/wwwroot/images/test-image.jpg b/Client/wwwroot/images/test-image.jpg
new file mode 100644
index 0000000..8e29493
Binary files /dev/null and b/Client/wwwroot/images/test-image.jpg differ
diff --git a/Server/Data/Database.cs b/Server/Data/Database.cs
index 2183663..6eff56b 100644
--- a/Server/Data/Database.cs
+++ b/Server/Data/Database.cs
@@ -13,30 +13,39 @@ namespace ShoppingCartStarter.Server.Data
///
/// Seed dummy cart data
///
- ///
- ///
public static void InitialiseDatabase(IApplicationBuilder app, IWebHostEnvironment env)
{
- using (var serviceScope = app.ApplicationServices.GetService().CreateScope())
- using (var context = serviceScope.ServiceProvider.GetRequiredService())
- {
- context.Database.Migrate();
+ using var serviceScope = app.ApplicationServices.GetService().CreateScope();
+ using var context = serviceScope.ServiceProvider.GetRequiredService();
+
+ context.Database.Migrate();
- if (!context.Carts.Any())
- {
- var cart = new ShoppingCart
- {
- LineItems = new List
- {
- new LineItem{ Image = "test-image.jpg", Name="Big T-shirt", Price=39.50m, Quantity = 2 },
- new LineItem{ Image = "test-image.jpg", Name="Small White T-shirt", Price=19.50m, Quantity = 1 },
- new LineItem{ Image = "test-image.jpg", Name="Smart Speaker", Price=23.00m, Quantity = 1 },
- }
- };
- context.Carts.Add(cart);
- context.SaveChanges();
- }
+ ShoppingCart cart;
+ if (context.Carts.Any())
+ {
+ cart = context.Carts
+ .Include(x=>x.LineItems)
+ .FirstOrDefault();
}
+ else
+ {
+ cart = new ShoppingCart();
+ context.Carts.Add(cart);
+ }
+
+ if (cart?.LineItems.Count == 0)
+ {
+ cart.LineItems.AddRange(new[]
+ {
+ new LineItem {Image = "test-image.jpg", Name = "Big T-shirt", Price = 39.50m, Quantity = 2},
+ new LineItem {Image = "test-image.jpg", Name = "Small White T-shirt", Price = 19.50m, Quantity = 1},
+ new LineItem {Image = "test-image.jpg", Name = "Smart Speaker", Price = 23.00m, Quantity = 1},
+ new LineItem {Image = "test-image.jpg", Name = "Dumb Speaker", Price = 99.00m, Quantity = 3},
+ new LineItem {Image = "test-image.jpg", Name = "Giraffe Poster", Price = 9.00m, Quantity = 20}
+ });
+ }
+
+ context.SaveChanges();
}
}
}
\ No newline at end of file