From ac84bee546deb5f90c2c34038fbc186c9ea32030 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 28 Dec 2021 12:04:19 +0300 Subject: [PATCH] Updated UI response for catalog service unavailability --- .../src/EShopOnAbp.PublicWeb/Pages/Index.cshtml | 15 +++++++++++---- .../EShopOnAbp.PublicWeb/Pages/Index.cshtml.cs | 17 +++++++++++++++-- .../Localization/EShopOnAbp/en.json | 1 + .../Localization/EShopOnAbp/tr.json | 1 + 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml index 9589b904..51c1ed81 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml @@ -6,21 +6,28 @@ @{ const int productsColumnSize = 4; // TODO: update abp-column helper to plain html for proper row and columns css + string pageHeader = L["OurProducts"]; } @section styles{ } + @section scripts { - - + + +} + +@if (Model.HasRemoteServiceError) +{ + pageHeader = L["CatalogServiceNotAvailable"]; }
-

@L["OurProducts"]

+

@pageHeader

- @for (int i = 0; i < Math.Ceiling(Model.Products.Count / (double)productsColumnSize); i++) + @for (int i = 0; i < Math.Ceiling(Model.Products.Count / (double) productsColumnSize); i++) { @for (int j = 0; j < productsColumnSize; j++) diff --git a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml.cs b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml.cs index 6191dd43..1b2f7b1e 100644 --- a/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml.cs +++ b/apps/public-web/src/EShopOnAbp.PublicWeb/Pages/Index.cshtml.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Threading.Tasks; using EShopOnAbp.CatalogService.Products; using Microsoft.AspNetCore.Authentication; @@ -9,6 +11,7 @@ namespace EShopOnAbp.PublicWeb.Pages public class IndexModel : AbpPageModel { public IReadOnlyList Products { get; private set; } + public bool HasRemoteServiceError { get; set; } = false; private readonly IPublicProductAppService _productAppService; public IndexModel(IPublicProductAppService productAppService) @@ -18,7 +21,17 @@ namespace EShopOnAbp.PublicWeb.Pages public async Task OnGet() { - Products = (await _productAppService.GetListAsync()).Items; + try + { + Products = (await _productAppService.GetListAsync()).Items; + } + catch (Exception e) + { + Products = new ReadOnlyCollection(new List()); + HasRemoteServiceError = true; + Console.WriteLine(e); + } + } public async Task OnPostLoginAsync() diff --git a/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/en.json b/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/en.json index 00b556ae..c6389ed1 100644 --- a/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/en.json +++ b/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/en.json @@ -6,6 +6,7 @@ "YourBasket": "Your Basket", "Total": "Total", "OurProducts": "Our Products", + "CatalogServiceNotAvailable": "Catalog Service is unavailable right now! Try again later...", "StockCount": "Stock Count", "RemoveFromBasket": "Remove from basket", "CompletePurchase": "Complete purchase", diff --git a/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/tr.json b/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/tr.json index 159c5c5e..7b0c9f7e 100644 --- a/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/tr.json +++ b/shared/EShopOnAbp.Shared.Localization/Localization/EShopOnAbp/tr.json @@ -6,6 +6,7 @@ "YourBasket": "Sepetiniz", "Total": "Toplam", "OurProducts": "Ürünlerimiz", + "CatalogServiceNotAvailable": "Ürün servisine şu anda ulaşılamıyor! Lütfen sonra tekrar deneyiniz...", "StockCount": "Stokta", "RemoveFromBasket": "Sepetten kaldır", "CompletePurchase": "Alışverişi tamamla",