From 12c6fb1426217656d4843f59d9e0ef40b1eb0df1 Mon Sep 17 00:00:00 2001 From: akv3sic Date: Sat, 4 Nov 2023 21:53:54 +0100 Subject: [PATCH] Add more comments and improve code style --- MauiStoreApp/Models/Category.cs | 2 +- MauiStoreApp/Services/CartService.cs | 2 +- MauiStoreApp/ViewModels/CartViewModel.cs | 1 + .../ViewModels/ProductDetailsViewModel.cs | 16 ++++++++++++---- MauiStoreApp/ViewModels/ProfilePageViewModel.cs | 7 +++++-- .../ViewModels/RecentlyViewedPageViewModel.cs | 4 ++++ 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/MauiStoreApp/Models/Category.cs b/MauiStoreApp/Models/Category.cs index 0bf94f3..2fbab85 100644 --- a/MauiStoreApp/Models/Category.cs +++ b/MauiStoreApp/Models/Category.cs @@ -28,7 +28,7 @@ public string ImageName return null; } - string formattedName = Name.Replace(" ", "_").Replace("'", "").ToLower(); + string formattedName = Name.Replace(" ", "_").Replace("'", string.Empty).ToLower(); return formattedName + ".jpg"; } } diff --git a/MauiStoreApp/Services/CartService.cs b/MauiStoreApp/Services/CartService.cs index 79f5c73..7c3a18b 100644 --- a/MauiStoreApp/Services/CartService.cs +++ b/MauiStoreApp/Services/CartService.cs @@ -67,7 +67,7 @@ public async Task RefreshCartItemsByUserIdAsync(int userId) _cartItems.Add(new CartItemDetail { Product = productDetails, - Quantity = cartProduct.Quantity + Quantity = cartProduct.Quantity, }); } } diff --git a/MauiStoreApp/ViewModels/CartViewModel.cs b/MauiStoreApp/ViewModels/CartViewModel.cs index 1a41c0a..019e227 100644 --- a/MauiStoreApp/ViewModels/CartViewModel.cs +++ b/MauiStoreApp/ViewModels/CartViewModel.cs @@ -62,6 +62,7 @@ public CartViewModel() /// /// Initializes the cart view model. /// + /// A representing the asynchronous operation. [RelayCommand] public async Task Init() { diff --git a/MauiStoreApp/ViewModels/ProductDetailsViewModel.cs b/MauiStoreApp/ViewModels/ProductDetailsViewModel.cs index 45ee476..d376be6 100644 --- a/MauiStoreApp/ViewModels/ProductDetailsViewModel.cs +++ b/MauiStoreApp/ViewModels/ProductDetailsViewModel.cs @@ -81,7 +81,7 @@ private async Task GetProductByIdAsync() catch (Exception ex) { Debug.WriteLine($"Unable to get product: {ex.Message}"); - await Shell.Current.DisplayAlert("Error!", ex.Message, "OK"); + await Shell.Current.DisplayAlert("Došlo je do pogreške!", ex.Message, "U redu"); } finally { @@ -92,7 +92,9 @@ private async Task GetProductByIdAsync() private async Task GetCrossSellProductsAsync() { if (IsBusy || Product == null) + { return; + } try { @@ -110,7 +112,7 @@ private async Task GetCrossSellProductsAsync() catch (Exception ex) { Debug.WriteLine($"Unable to get cross-sell products: {ex.Message}"); - await Shell.Current.DisplayAlert("Error!", ex.Message, "OK"); + await Shell.Current.DisplayAlert("Došlo je do pogreške!", ex.Message, "U redu"); } finally { @@ -128,11 +130,13 @@ private async Task ProductTapped(Product product) IsBusy = true; if (product == null) + { return; + } var navigationParameter = new Dictionary { - { "Product", product } + { "Product", product }, }; _recentlyViewedProductsService.AddProduct(product); @@ -156,7 +160,7 @@ private async Task ShareProduct(Product product) { Uri = product.Image, Title = product.Title, - Text = "Check out this product on AStore!" + Text = "Pogledaj ovaj proizvod na AStore!", }); } @@ -168,12 +172,16 @@ private async Task ShareProduct(Product product) private async Task AddToCart(Product product) { if (IsBusy) + { return; + } try { if (product == null) + { return; + } _cartService.AddProductToCart(product); diff --git a/MauiStoreApp/ViewModels/ProfilePageViewModel.cs b/MauiStoreApp/ViewModels/ProfilePageViewModel.cs index 5ba49e9..cb03983 100644 --- a/MauiStoreApp/ViewModels/ProfilePageViewModel.cs +++ b/MauiStoreApp/ViewModels/ProfilePageViewModel.cs @@ -54,6 +54,7 @@ public ProfilePageViewModel() /// /// Initializes the view model. /// + /// A representing the asynchronous operation. [RelayCommand] public async Task Init() { @@ -64,7 +65,9 @@ public async Task Init() private async Task GetUserByIdAsync() { if (IsBusy) + { return; + } try { @@ -105,8 +108,8 @@ private async Task GetUserByIdAsync() [RelayCommand] private async Task Logout() { - // fire alert - var result = await Shell.Current.DisplayAlert("Odjava", "Jeste li sigurni da se želite odjaviti?", "Da", "Ne"); + // fire alert + var result = await Shell.Current.DisplayAlert("Odjava", "Jeste li sigurni da se želite odjaviti?", "Da", "Ne"); if (result) { diff --git a/MauiStoreApp/ViewModels/RecentlyViewedPageViewModel.cs b/MauiStoreApp/ViewModels/RecentlyViewedPageViewModel.cs index 2596e39..055c978 100644 --- a/MauiStoreApp/ViewModels/RecentlyViewedPageViewModel.cs +++ b/MauiStoreApp/ViewModels/RecentlyViewedPageViewModel.cs @@ -61,7 +61,9 @@ private async Task ProductTapped(Product product) IsBusy = true; if (product == null) + { return; + } var navigationParameter = new Dictionary { @@ -92,7 +94,9 @@ private async Task DeleteAll() var result = await Shell.Current.DisplayAlert("Brisanje", "Sigurno želite izbrisati sve nedavno gledane proizvode?", "Da", "Ne"); if (!result) + { return; // Exit if user cancels + } RecentlyViewedProductsService.RecentlyViewedProducts.Clear(); RecentlyViewedProductsService.SaveProducts();