Skip to content

Commit

Permalink
Add more comments and improve code style
Browse files Browse the repository at this point in the history
  • Loading branch information
akv3sic committed Nov 4, 2023
1 parent 7059587 commit 12c6fb1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion MauiStoreApp/Models/Category.cs
Expand Up @@ -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";
}
}
Expand Down
2 changes: 1 addition & 1 deletion MauiStoreApp/Services/CartService.cs
Expand Up @@ -67,7 +67,7 @@ public async Task RefreshCartItemsByUserIdAsync(int userId)
_cartItems.Add(new CartItemDetail
{
Product = productDetails,
Quantity = cartProduct.Quantity
Quantity = cartProduct.Quantity,
});
}
}
Expand Down
1 change: 1 addition & 0 deletions MauiStoreApp/ViewModels/CartViewModel.cs
Expand Up @@ -62,6 +62,7 @@ public CartViewModel()
/// <summary>
/// Initializes the cart view model.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
[RelayCommand]
public async Task Init()
{
Expand Down
16 changes: 12 additions & 4 deletions MauiStoreApp/ViewModels/ProductDetailsViewModel.cs
Expand Up @@ -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
{
Expand All @@ -92,7 +92,9 @@ private async Task GetProductByIdAsync()
private async Task GetCrossSellProductsAsync()
{
if (IsBusy || Product == null)
{
return;
}

try
{
Expand All @@ -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
{
Expand All @@ -128,11 +130,13 @@ private async Task ProductTapped(Product product)
IsBusy = true;

if (product == null)
{
return;
}

var navigationParameter = new Dictionary<string, object>
{
{ "Product", product }
{ "Product", product },
};

_recentlyViewedProductsService.AddProduct(product);
Expand All @@ -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!",
});
}

Expand All @@ -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);

Expand Down
7 changes: 5 additions & 2 deletions MauiStoreApp/ViewModels/ProfilePageViewModel.cs
Expand Up @@ -54,6 +54,7 @@ public ProfilePageViewModel()
/// <summary>
/// Initializes the view model.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
[RelayCommand]
public async Task Init()
{
Expand All @@ -64,7 +65,9 @@ public async Task Init()
private async Task GetUserByIdAsync()
{
if (IsBusy)
{
return;
}

try
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions MauiStoreApp/ViewModels/RecentlyViewedPageViewModel.cs
Expand Up @@ -61,7 +61,9 @@ private async Task ProductTapped(Product product)
IsBusy = true;

if (product == null)
{
return;
}

var navigationParameter = new Dictionary<string, object>
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 12c6fb1

Please sign in to comment.