@page "/store/cart" @attribute [Authorize]

Cart

@foreach( MistoxWebsite.Shared.Database.Cart obj in Statics.Carts ) {

@getItem(obj.ProductID)?.Name

@foreach( string cur in getItem( obj.ProductID )?.Images ) { Not found }

$@((Convert.ToSingle( getItem( obj.ProductID )?.Cost ) / 100f).ToString( "0.00" )) USD

}
@if( Statics.Carts.Count > 0 ) {

Total : $@total.ToString( "0.00" )

} else {

The cart is empty

}
@code { [Parameter] public Func? ShouldReRender { get; set; } [Parameter] public Catalog? parent { get; set; } = null; float total = 0; Product? getItem(int productID ) { foreach(Product cur in Statics.Products ) { if (cur.ID == productID ) { return cur; } } return null; } protected override void OnInitialized() { total = 0; foreach( MistoxWebsite.Shared.Database.Cart obj in Statics.Carts ) { foreach( Product item in Statics.Products ) { if( obj.ProductID == item.ID ) { total = total + (item.Cost / 100f); break; } } } base.StateHasChanged(); } public void RecalcTotal() { OnInitialized(); } public async void removeFromCart(int ID) { for(int i=0; i<=Statics.Carts.Count; i++ ) { if(ID == Statics.Carts[i].ProductID ) { await Http.PostAsJsonAsync( "api/cart/remove", Statics.Carts [i] ); Statics.Carts.RemoveAt(i); total = 0; OnInitialized(); break; } } if (parent != null ) { parent?.Refresh(); } else { base.StateHasChanged(); } } public void Chekout() { Nav.NavigateTo("/store/payment/checkout"); } }