From 64e0fcba274cbdc6414f496970d0cea6da2063df Mon Sep 17 00:00:00 2001 From: Khwezi Mngoma Date: Wed, 10 Jun 2026 23:01:21 +0200 Subject: [PATCH] Wired up CartDrawel and ProductView to cart service and local storage --- .../Components/Layout/MainLayout.razor | 27 ++++++---- .../Components/Layout/MainLayout.razor.cs | 37 ++++++-------- .../Components/Pages/ProductView.razor.cs | 50 ++++++++++++++----- .../Services/ShoppingCart/CartService.cs | 23 ++++----- .../Services/ShoppingCart/Models/CartItem.cs | 9 +++- 5 files changed, 85 insertions(+), 61 deletions(-) diff --git a/MidrandBookshop/Components/Layout/MainLayout.razor b/MidrandBookshop/Components/Layout/MainLayout.razor index 3090d41..747a64e 100644 --- a/MidrandBookshop/Components/Layout/MainLayout.razor +++ b/MidrandBookshop/Components/Layout/MainLayout.razor @@ -6,7 +6,7 @@
- YOUR CART (@CartItems.Sum(i => i.Quantity)) + YOUR CART (@ShoppingCart.Items.Count())
- @if (!CartItems.Any()) + @if (!ShoppingCart.Items.Any()) {
@@ -29,22 +29,29 @@ else {
- @foreach (var item in CartItems) + @foreach (var item in ShoppingCart.Items) {
- [ COVER ] + @if (!string.IsNullOrWhiteSpace(item.Product!.ImageUrl)) + { + @item.Product.Name + } + else + { + @:[COVER] + }
-
@item.Title
-

by @item.Author

+
@item.Product!.Name
+

by @($"{item.Author!.Name} {item.Author.LastName}")

- @item.Quantity + @ShoppingCart.Items.FirstOrDefault(i => i.Price!.Id == item.Price!.Id)!.Quantity
- R @(item.Price * item.Quantity) + R @(item.Price!.Amount * item.Quantity)
- @if (CartItems.Any()) + @if (ShoppingCart.Items.Any()) {