@page @using Northwind.Web.Pages @using Packt.Shared @model FunctionsModel @{ string title = "Functions"; ViewData["Title"] = $"Northwind B2B - {title}"; string collapsedTimesTable = Model.TimesTableNumberInput.HasValue ? string.Empty : "collapse"; string collapsedCalculateTax = Model.Amount.HasValue ? string.Empty : "collapse"; string collapsedFactorial = Model.FactorialNumber.HasValue ? string.Empty : "collapse"; string collapsedFibonacci = Model.FibonacciNumber.HasValue ? string.Empty : "collapse"; }

@title

Exercise 14.3 – Practice building web pages for console apps

Provide a web user interface to output times tables, calculate tax, and generate factorials and the Fibonacci sequence.

Enter an integer between 1 and 100.
@if (Model.TimesTableNumberInput.HasValue) {
@Model.TimesTableNumberInput times table
@for (int i = 1; i <= 12; i++) {
@i x @Model.TimesTableNumberInput = @(i * Model.TimesTableNumberInput)
}
}

Enter a monetary value.
Select a European or US state.
@if (Model.Amount.HasValue) {
You must pay @Model.TaxToPay in tax.
}

Enter an integer between 1 and 12.
@if (Model.FactorialNumber.HasValue) {
@(Model.FactorialNumber)!
@(Model.FactorialNumber)! = @(Model.FactorialResult is null ? "null" : Model.FactorialResult.Value.ToString("N0"))
} @if (Model.FactorialException is not null) {
Exception
@Model.FactorialException.Message
}

Enter an integer between 1 and 40.
@if (Model.FibonacciNumber.HasValue) {
Fibonacci term @Model.FibonacciNumber
Term @Model.FibonacciNumber of the fibonacci sequence = @(Model.FibonacciResult is null ? "null" : Model.FibonacciResult.Value.ToString("N0"))
}