@page "/"
<h1>Bagel Store</h1>
<div>
<label for="txtBagelCount">Number of Bagels: </label>
<input id="txtBagelCount" @bind="BagelCount" @bind:event="oninput" />
</div>
<div id="divBagelKind">
<label for="divBagelKind">Kind of Bagel: </label>
<input type="radio" name="rbgBagelKind" value="Plain" id="rdbPlain" @onchange="OnChangeKind" checked />
<label for="rdbPlain">Plain</label>
<input type="radio" name="rbgBagelKind" value="Wheat" id="rdbWheat" @onchange="OnChangeKind" />
<label for="rdbWheat">Wheat</label>
<input type="radio" name="rbgBagelKind" value="Everything" id="rdbEverything" @onchange="OnChangeKind" />
<label for="rdbEverything">Everything</label>
</div>
<div id="divOptions">
<label for="divOptions">Options: </label>
<input type="checkbox" id="chkToasted" @bind="IsToasted" />
<label for="chkToasted">Toasted</label>
<input type="checkbox" id="chkCreamCheese" @bind="IsCreamCheese" />
<label for="chkCreamCheese">Cream Cheese</label>
</div>
<div id="divDineIn">
<input type="checkbox" id="chkDineIn" @bind="IsDineIn" />
<label for="chkDineIn">Dine In</label>
</div>
<div>
<label>Tax: @subTotal.ToString("C")</label>
</div>
<div>
<label>Tax: @tax.ToString("C")</label>
</div>
<div>
<label>Total Cost: @totalCost.ToString("C")</label>
</div>
@code
{
int _bagelCount = 0;
int BagelCount { get => _bagelCount; set { _bagelCount = value; Recompute(); } }
string _bagelKind;
string BagelKind { get => _bagelKind; set { _bagelKind = value; Recompute(); } }
bool _isToasted;
bool IsToasted { get => _isToasted; set { _isToasted = value; Recompute(); } }
bool _isCreamCheese;
bool IsCreamCheese { get => _isCreamCheese; set { _isCreamCheese = value; Recompute(); } }
bool _isDineIn;
bool IsDineIn { get => _isDineIn; set { _isDineIn = value; Recompute(); } }
decimal subTotal;
decimal tax;
decimal totalCost;
void OnChangeKind(ChangeEventArgs e)
=> BagelKind = e.Value.ToString();
void Recompute()
{
subTotal = 2.0m;
switch (BagelKind)
{
case "Wheat":
subTotal += 0.50m;
break;
case "Everything":
subTotal += 1.50m;
break;
}
if (IsToasted)
subTotal += 0.50m;
if (IsCreamCheese)
subTotal += 1.0m;
subTotal *= BagelCount;
tax = 0;
if (IsDineIn)
tax = subTotal * 0.07m;
totalCost = subTotal + tax;
}
}