Commit 0df94606 authored by Ryan Nowak's avatar Ryan Nowak
Browse files

Use a range instead of button group

parent 84e28c1f
......@@ -75,7 +75,7 @@
{
Special = special,
SpecialId = special.Id,
Size = PizzaSize.Medium,
Size = Pizza.DefaultSize,
Toppings = new List<PizzaTopping>(),
};
......
......@@ -31,7 +31,7 @@
{
<p>
<strong>
@(Pizza.GetSizeInInches(pizza.Size))"
@(pizza.Size)"
@pizza.Special.Name
(£@pizza.GetFormattedTotalPrice())
</strong>
......
......@@ -9,16 +9,11 @@
<form class="dialog-body">
<div class="row form-group">
<label class="col-md-4 col-form-label">Size:</label>
<div class="col-md-8">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
@foreach (PizzaSize size in Enum.GetValues(typeof(PizzaSize)))
{
<label class="btn btn-secondary @(Pizza.Size == size ? "active" : "")">
<input type="radio" name="size" autocomplete="off" value="@size" checked="@(Pizza.Size == size)" onchange="@SizeSelected" /> @(Pizza.GetSizeInInches(size))"
</label>
}
</div>
<label>£@(Pizza.GetFormattedTotalPrice())</label>
<div class="col-md-6">
<input type="range" class="form-control-range" min="@Pizza.MinimumSize" max="@Pizza.MaximumSize" step="1" bind="Pizza.Size"/>
</div>
<div class="col-md-2">
<label>@(Pizza.Size)" £@(Pizza.GetFormattedTotalPrice())</label>
</div>
</div>
@if (AllToppings == null)
......@@ -88,14 +83,6 @@
AllToppings = await HttpClient.GetJsonAsync<List<Topping>>("/toppings");
}
void SizeSelected(UIChangeEventArgs e)
{
if (Enum.TryParse<PizzaSize>((string)e.Value, out var size))
{
Pizza.Size = size;
}
}
void ToppingSelected(UIChangeEventArgs e)
{
if (int.TryParse((string)e.Value, out var index) && index >= 0)
......
<div class="cart-item">
<a onclick=@OnRemoved class="delete-item">x</a>
<div class="title">@(Pizza.GetSizeInInches(Pizza.Size))" @Pizza.Special.Name</div>
<div class="title">@(Pizza.Size)" @Pizza.Special.Name</div>
<ul>
@foreach (var topping in Pizza.Toppings)
{
......
......@@ -11,6 +11,10 @@ namespace BlazingPizza
/// </summary>
public class Pizza
{
public const int DefaultSize = 12;
public const int MinimumSize = 9;
public const int MaximumSize = 17;
public int Id { get; set; }
public int OrderId { get; set; }
......@@ -19,26 +23,13 @@ namespace BlazingPizza
public int SpecialId { get; set; }
public PizzaSize Size { get; set; }
public int Size { get; set; }
public List<PizzaTopping> Toppings { get; set; }
public decimal GetBasePrice()
{
switch (Size)
{
case PizzaSize.Small:
return Special.BasePrice * .75m;
case PizzaSize.Medium:
return Special.BasePrice * 1.00m;
case PizzaSize.Large:
return Special.BasePrice * 1.25m;
default:
throw new InvalidOperationException();
}
return ((decimal)Size / (decimal)DefaultSize) * Special.BasePrice;
}
public decimal GetTotalPrice()
......
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