diff --git a/ContosoPizza/ContosoPizza.db b/ContosoPizza/ContosoPizza.db index a1f9119..f732bd0 100644 Binary files a/ContosoPizza/ContosoPizza.db and b/ContosoPizza/ContosoPizza.db differ diff --git a/ContosoPizza/Pages/Index.cshtml b/ContosoPizza/Pages/Index.cshtml index b5f0c15..2094927 100644 --- a/ContosoPizza/Pages/Index.cshtml +++ b/ContosoPizza/Pages/Index.cshtml @@ -1,10 +1,13 @@ @page @model IndexModel @{ - ViewData["Title"] = "Home page"; + ViewData["Title"] = "The Home for Pizza Lovers"; + TimeSpan timeInBusiness = DateTime.Now - new DateTime(2018, 8, 14); }
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Welcome to Contoso Pizza

+

+ The best pizza in town for @Convert.ToInt32(timeInBusiness.TotalDays) days! +

diff --git a/ContosoPizza/Pages/PizzaList.cshtml b/ContosoPizza/Pages/PizzaList.cshtml new file mode 100644 index 0000000..45a7ae0 --- /dev/null +++ b/ContosoPizza/Pages/PizzaList.cshtml @@ -0,0 +1,99 @@ +@page +@model CotosoPizza.Pages.PizzaListModel +@{ + ViewData["Title"] = "Pizza List 🍕"; +} + +

Pizza List 🍕

+ +
+
+
+ + + +
+
+ + + +
+
+ +
+
+ + + +
+
+ +
+
+ + + + + + + + + + + + + + + @foreach (var pizza in Model.PizzaList) + { + + + + + + + + } + +
NamePriceSizeGluten FreeDelete
@pizza.Name@($"{pizza.Price:C}")@pizza.Size@(pizza.IsGlutenFree ? "✔️" : string.Empty) +
+ +
+
+ + + + + + + + + + + @foreach (var pizza in Model.PizzaList) + { + + + + + + + + } + +
NamePriceSizeGluten FreeDelete
@pizza.Name@($"{pizza.Price:C}")@pizza.Size@(pizza.IsGlutenFree ? "✔️" : string.Empty) +
+ +
+
+ +@section Scripts { + +} \ No newline at end of file diff --git a/ContosoPizza/Pages/PizzaList.cshtml.cs b/ContosoPizza/Pages/PizzaList.cshtml.cs new file mode 100644 index 0000000..4acf909 --- /dev/null +++ b/ContosoPizza/Pages/PizzaList.cshtml.cs @@ -0,0 +1,44 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using ContosoPizza.Models; +using ContosoPizza.Services; + +namespace CotosoPizza.Pages +{ + public class PizzaListModel : PageModel + { + private readonly PizzaService _service; + public IList PizzaList { get; set; } = default!; + + [BindProperty] + public Pizza NewPizza { get; set; } = default!; + + public PizzaListModel(PizzaService service) + { + _service = service; + } + + public void OnGet() + { + PizzaList = _service.GetPizzas(); + } + + public IActionResult OnPost() + { + if (!ModelState.IsValid || NewPizza == null) + { + return Page(); + } + + _service.AddPizza(NewPizza); + return RedirectToAction("Get"); + } + + public IActionResult OnPostDelete(int id) + { + _service.DeletePizza(id); + + return RedirectToAction("Get"); + } + } +} diff --git a/ContosoPizza/Pages/Shared/_Layout.cshtml b/ContosoPizza/Pages/Shared/_Layout.cshtml index ff24a5c..5583e40 100644 --- a/ContosoPizza/Pages/Shared/_Layout.cshtml +++ b/ContosoPizza/Pages/Shared/_Layout.cshtml @@ -22,6 +22,9 @@ + diff --git a/ContosoPizza/Program.cs b/ContosoPizza/Program.cs index 5c6dd50..292c811 100644 --- a/ContosoPizza/Program.cs +++ b/ContosoPizza/Program.cs @@ -9,6 +9,7 @@ builder.Services.AddRazorPages(); builder.Services.AddDbContext(options => options.UseSqlite("Data Source=ContosoPizza.db")); +builder.Services.AddScoped(); var app = builder.Build();