Refactor CartService to use async methods for cart operations and integrate gRPC for backend synchronization

This commit is contained in:
masoodafar-web
2025-11-20 20:10:17 +03:30
parent ddb47fda08
commit 30bac23114
7 changed files with 107 additions and 14 deletions

View File

@@ -14,14 +14,14 @@ public partial class Cart : ComponentBase, IDisposable
CartService.OnChange += StateHasChanged;
}
private void ChangeQty(long productId, int value)
private async Task ChangeQty(long productId, int value)
{
CartService.UpdateQuantity(productId, value);
await CartService.UpdateQuantity(productId, value);
}
private void Remove(long productId)
private async Task Remove(long productId)
{
CartService.Remove(productId);
await CartService.Remove(productId);
}
private void ProceedCheckout()

View File

@@ -72,7 +72,7 @@ public partial class CheckoutSummary : ComponentBase
};
var id = await OrderService.CreateOrderAsync(order);
Cart.Clear();
await Cart.Clear();
Snackbar.Add("سفارش با موفقیت ثبت شد.", Severity.Success);
Navigation.NavigateTo($"{RouteConstants.Store.OrderDetail}{id}");
}

View File

@@ -21,10 +21,10 @@ public partial class ProductDetail : ComponentBase
_loading = false;
}
private void AddToCart()
private async Task AddToCart()
{
if (_product is null) return;
Cart.Add(_product, _qty);
await Cart.Add(_product, _qty);
}
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);

View File

@@ -31,9 +31,9 @@ public partial class Products : ComponentBase, IDisposable
await Load();
}
private void AddToCart(Product p)
private async Task AddToCart(Product p)
{
Cart.Add(p, 1);
await Cart.Add(p, 1);
}
private static string FormatPrice(long price) => string.Format("{0:N0} تومان", price);