Commit d2adaee5 authored by Ryan Nowak's avatar Ryan Nowak
Browse files

Cleanup price formatting on index

parent 60c045f4
......@@ -12,7 +12,7 @@
<div class="pizza-info">
<span class="title">@special.Name</span>
@special.Description
<span class="price">@special.BasePrice.ToString("0.00")</span>
<span class="price">@special.GetFormattedBasePrice()</span>
</div>
</li>
}
......@@ -21,12 +21,12 @@
</div>
<div class="sidebar">
@if (configuredPizzas.Any())
@if (order.Pizzas.Any())
{
<div class="order-contents">
<h2>Your order</h2>
@foreach (var configuredPizza in configuredPizzas)
@foreach (var configuredPizza in order.Pizzas)
{
<ConfiguredPizzaItem Pizza="configuredPizza" OnRemoved="() => RemoveConfiguredPizza(configuredPizza)" />
}
......@@ -37,10 +37,10 @@
<div class="empty-cart">Choose a pizza<br>to get started</div>
}
<div class="order-total @(configuredPizzas.Any() ? "" : "hidden")">
<div class="order-total @(order.Pizzas.Any() ? "" : "hidden")">
Total:
<span class="total-price">@OrderPrice.ToString("0.00")</span>
<button class="btn btn-warning" disabled="@(configuredPizzas.Count == 0)" onclick="@PlaceOrder">
<span class="total-price">@order.GetFormattedTotalPrice()</span>
<button class="btn btn-warning" disabled="@(order.Pizzas.Count == 0)" onclick="@PlaceOrder">
Order >
</button>
</div>
......@@ -60,12 +60,10 @@
bool showConfigurePizzaDialog;
Pizza pizza;
List<Pizza> configuredPizzas = new List<Pizza>();
Order order = new Order();
List<PizzaSpecial> specials;
decimal OrderPrice => configuredPizzas.Sum(p => p.GetTotalPrice());
protected async override Task OnInitAsync()
{
specials = await HttpClient.GetJsonAsync<List<PizzaSpecial>>("/specials");
......@@ -94,7 +92,7 @@
void ConfirmConfigurePizzaDialog()
{
configuredPizzas.Add(pizza);
order.Pizzas.Add(pizza);
pizza = null;
showConfigurePizzaDialog = false;
......@@ -103,23 +101,18 @@
void RemoveConfiguredPizza(Pizza pizza)
{
configuredPizzas.Remove(pizza);
order.Pizzas.Remove(pizza);
StateHasChanged();
}
async Task PlaceOrder()
{
var order = new Order()
{
Pizzas = configuredPizzas,
};
// The server will reject the submission if you're not signed in, so attempt
// to sign in first if needed
if (await UserState.TrySignInAsync())
{
await HttpClient.PostJsonAsync("/orders", order);
configuredPizzas.Clear();
order = new Order();
UriHelper.NavigateTo("myorders");
}
}
......
......@@ -14,8 +14,10 @@ namespace BlazingPizza
public LatLong DeliveryLocation { get; set; }
public List<Pizza> Pizzas { get; set; }
public List<Pizza> Pizzas { get; set; } = new List<Pizza>();
public decimal GetTotalPrice() => Pizzas.Sum(p => p.GetTotalPrice());
public string GetFormattedTotalPrice() => GetTotalPrice().ToString("0.00");
}
}
......@@ -14,5 +14,7 @@
public string Description { get; set; }
public string ImageUrl { get; set; }
public string GetFormattedBasePrice() => BasePrice.ToString("0.00");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment