From 48dadf007a7d749afc7ed0f1defb1d6883cdded2 Mon Sep 17 00:00:00 2001 From: masoodafar-web Date: Fri, 28 Nov 2025 13:35:26 +0330 Subject: [PATCH] Update order pages with error handling and improved product images --- src/FrontOffice.Main/Pages/Store/Cart.razor | 18 +++++++------ .../Pages/Store/Cart.razor.cs | 3 +++ .../Pages/Store/CheckoutSummary.razor | 26 ++++++++++++------- .../Pages/Store/CheckoutSummary.razor.cs | 3 +++ .../Pages/Store/OrderDetail.razor | 8 +++--- .../Pages/Store/OrderDetail.razor.cs | 3 +++ src/FrontOffice.Main/Pages/Store/Orders.razor | 4 +-- .../Pages/Store/Orders.razor.cs | 17 ++++++++++-- .../Utilities/OrderService.cs | 22 ++++++++++++++-- src/FrontOffice.Main/wwwroot/css/site.css | 6 +++++ .../wwwroot/images/product-placeholder.svg | 5 ++++ 11 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 src/FrontOffice.Main/wwwroot/images/product-placeholder.svg diff --git a/src/FrontOffice.Main/Pages/Store/Cart.razor b/src/FrontOffice.Main/Pages/Store/Cart.razor index 05d15df..8772047 100644 --- a/src/FrontOffice.Main/Pages/Store/Cart.razor +++ b/src/FrontOffice.Main/Pages/Store/Cart.razor @@ -30,7 +30,8 @@ - + @context.Title @if (context.Discount > 0 || !string.IsNullOrWhiteSpace(context.Created) || !string.IsNullOrWhiteSpace(context.Description)) @@ -85,7 +86,8 @@ - + @item.Title @if (item.Discount > 0) @@ -99,11 +101,11 @@ { - @if (!string.IsNullOrWhiteSpace(item.Description)) - { - @item.Description - } + @* @if (!string.IsNullOrWhiteSpace(item.Description)) *@ + @* { *@ + @* @item.Description *@ + @* } *@ @* @if (!string.IsNullOrWhiteSpace(item.Created)) *@ @* { *@ @* تاریخ افزودن: @item.Created *@ @@ -151,7 +153,7 @@ OnClick="() => Navigation.NavigateTo(RouteConstants.Store.Products)">افزودن محصول ادامه فرایند خرید + StartIcon="@Icons.Material.Filled.CreditCard">ادامه خرید } diff --git a/src/FrontOffice.Main/Pages/Store/Cart.razor.cs b/src/FrontOffice.Main/Pages/Store/Cart.razor.cs index 3bb472c..c8f1e7e 100644 --- a/src/FrontOffice.Main/Pages/Store/Cart.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/Cart.razor.cs @@ -46,6 +46,9 @@ public partial class Cart : ComponentBase, IDisposable private static string FormatPrice(long price) => string.Format("{0:N0} ", price); + private static string GetProductImageUrl(string? imageUrl) + => string.IsNullOrWhiteSpace(imageUrl) ? "/images/product-placeholder.svg" : imageUrl; + public void Dispose() { CartService.OnChange -= StateHasChanged; diff --git a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor index 982ffe6..fb8aaac 100644 --- a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor +++ b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor @@ -79,16 +79,24 @@ @foreach (var item in Cart.Items) { - - - @item.Title x @item.Quantity - @FormatPrice(item.LineTotal) + + + + + + @item.Title + @FormatPrice(item.LineTotal) + + + تعداد: @item.Quantity + @if (item.Discount > 0) + { + @($"تخفیف: {item.Discount}%") + } + - @if (item.Discount > 0) - { - @($"تخفیف: {item.Discount}%") - } - + } diff --git a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs index 11e6b27..3096d99 100644 --- a/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/CheckoutSummary.razor.cs @@ -90,4 +90,7 @@ public partial class CheckoutSummary : ComponentBase } private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price); + + private static string GetProductImageUrl(string? imageUrl) + => string.IsNullOrWhiteSpace(imageUrl) ? "/images/product-placeholder.svg" : imageUrl; } \ No newline at end of file diff --git a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor index 08a4f47..d473c56 100644 --- a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor +++ b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor @@ -40,8 +40,9 @@ else - - @context.ProductTitle + + @context.ProductThumbnailPath @FormatPrice(context.UnitPrice.Value) @@ -58,7 +59,8 @@ else - + @it.ProductTitle diff --git a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs index 0ead158..8389982 100644 --- a/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/OrderDetail.razor.cs @@ -42,5 +42,8 @@ public partial class OrderDetail : ComponentBase _ => "نامشخص", }; } + + private static string GetProductImageUrl(string? imageUrl) + => string.IsNullOrWhiteSpace(imageUrl) ? "/images/product-placeholder.svg" : UrlUtility.DownloadUrl+imageUrl; } diff --git a/src/FrontOffice.Main/Pages/Store/Orders.razor b/src/FrontOffice.Main/Pages/Store/Orders.razor index 97b9321..1355e6d 100644 --- a/src/FrontOffice.Main/Pages/Store/Orders.razor +++ b/src/FrontOffice.Main/Pages/Store/Orders.razor @@ -32,7 +32,7 @@ @GetStatusText(context.PaymentStatus) @FormatPrice(context.FactorDetails.Sum(s=>s.UnitPrice.Value*s.Count.Value)) - جزئیات + جزئیات @@ -50,7 +50,7 @@ وضعیت: @GetStatusText(o.PaymentStatus) - @FormatPrice(o.FactorDetails.Sum(s=>s.UnitPrice.Value*s.Count.Value))) + @FormatPrice(o.FactorDetails.Sum(s=>s.UnitPrice.Value*s.Count.Value)) جزئیات diff --git a/src/FrontOffice.Main/Pages/Store/Orders.razor.cs b/src/FrontOffice.Main/Pages/Store/Orders.razor.cs index c897c77..6053be7 100644 --- a/src/FrontOffice.Main/Pages/Store/Orders.razor.cs +++ b/src/FrontOffice.Main/Pages/Store/Orders.razor.cs @@ -1,6 +1,8 @@ +using System; using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder; using FrontOffice.Main.Utilities; using Microsoft.AspNetCore.Components; +using MudBlazor; namespace FrontOffice.Main.Pages.Store; @@ -14,8 +16,19 @@ public partial class Orders : ComponentBase protected override async Task OnInitializedAsync() { _loading = true; - _orders = await OrderService.GetOrdersAsync(); - _loading = false; + try + { + _orders = await OrderService.GetOrdersAsync(); + } + catch (Exception ex) + { + Snackbar.Add($"خطا در بارگذاری سفارش‌ها: {ex.Message}", Severity.Error); + _orders = new List(); + } + finally + { + _loading = false; + } } private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price); diff --git a/src/FrontOffice.Main/Utilities/OrderService.cs b/src/FrontOffice.Main/Utilities/OrderService.cs index a622f1c..6112233 100644 --- a/src/FrontOffice.Main/Utilities/OrderService.cs +++ b/src/FrontOffice.Main/Utilities/OrderService.cs @@ -1,4 +1,5 @@ using FrontOffice.BFF.UserOrder.Protobuf.Protos.UserOrder; +using Mapster; namespace FrontOffice.Main.Utilities; @@ -41,9 +42,26 @@ public class OrderService _userOrderContractClient = userOrderContractClient; } - public Task> GetOrdersAsync() + public async Task> GetOrdersAsync() { - return Task.FromResult(_orders.OrderByDescending(o => o.PaymentDate).ToList()); + var result = await _userOrderContractClient.GetAllUserOrderByFilterAsync(new()); + if (result != null && result.Models.Count > 0) + { + foreach (var item in result.Models) + { + var order = new GetUserOrderResponse(); + if (_orders.All(a => a.Id != item.Id)) + { + TypeAdapterConfig.GlobalSettings.NewConfig() + .Map(dest => dest.ProductThumbnailPath, src => src.ProductThumbnailPath); + order= item.Adapt(); + order.FactorDetails.AddRange(item.FactorDetails.Adapt>()); + _orders.Add(order); + } + } + } + + return _orders.OrderByDescending(o => o.PaymentDate).ToList(); } public async Task GetOrderAsync(long id) diff --git a/src/FrontOffice.Main/wwwroot/css/site.css b/src/FrontOffice.Main/wwwroot/css/site.css index a14fb33..b983cb2 100644 --- a/src/FrontOffice.Main/wwwroot/css/site.css +++ b/src/FrontOffice.Main/wwwroot/css/site.css @@ -383,6 +383,12 @@ html, body { .mobile-actions-stack { width: 100%; display: flex; gap: .5rem; } .mobile-actions-stack > * { flex: 1; } } +.product-thumb { + border-radius: 12px; + object-fit: cover; + display: block; + box-shadow: 0 2px 6px rgba(0,0,0,.08); +} /*#endregion*/ /*#region Profile Tiles*/ diff --git a/src/FrontOffice.Main/wwwroot/images/product-placeholder.svg b/src/FrontOffice.Main/wwwroot/images/product-placeholder.svg new file mode 100644 index 0000000..fcfe7ed --- /dev/null +++ b/src/FrontOffice.Main/wwwroot/images/product-placeholder.svg @@ -0,0 +1,5 @@ + + + + +