From 38a0af99253bc0cb0e6251b89ab7b9cec22c1bbc Mon Sep 17 00:00:00 2001 From: Peace Date: Wed, 12 Jun 2024 11:33:50 +0900 Subject: [PATCH] add pizza list page --- WebUIWithRazor/ContosoPizza.db-shm | Bin 0 -> 32768 bytes WebUIWithRazor/ContosoPizza.db-wal | 0 WebUIWithRazor/Pages/PizzaList.cshtml | 35 +++++++++++++++++++++ WebUIWithRazor/Pages/PizzaList.cshtml.cs | 23 ++++++++++++++ WebUIWithRazor/Pages/Shared/_Layout.cshtml | 3 ++ WebUIWithRazor/Program.cs | 2 ++ 6 files changed, 63 insertions(+) create mode 100644 WebUIWithRazor/ContosoPizza.db-shm create mode 100644 WebUIWithRazor/ContosoPizza.db-wal create mode 100644 WebUIWithRazor/Pages/PizzaList.cshtml create mode 100644 WebUIWithRazor/Pages/PizzaList.cshtml.cs diff --git a/WebUIWithRazor/ContosoPizza.db-shm b/WebUIWithRazor/ContosoPizza.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10 GIT binary patch literal 32768 zcmeIuAr62r3Pizza List 🍕 + + + + + + + + + + + + + @foreach (var pizza in Model.PizzaList) + { + + + + + + + + } + +
NamePriceSizeGluten FreeDelete
@pizza.Name@($"{pizza.Price:C}")@pizza.Size@(pizza.IsGlutenFree ? "✔️" : string.Empty) +
+ +
+
\ No newline at end of file diff --git a/WebUIWithRazor/Pages/PizzaList.cshtml.cs b/WebUIWithRazor/Pages/PizzaList.cshtml.cs new file mode 100644 index 0000000..636ba71 --- /dev/null +++ b/WebUIWithRazor/Pages/PizzaList.cshtml.cs @@ -0,0 +1,23 @@ +using ContosoPizza.Models; +using ContosoPizza.Services; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace ContosoPizza.Pages +{ + public class PizzaListModel : PageModel + { + private readonly PizzaService _service; + public IList PizzaList { get; set; } = default; + + public PizzaListModel(PizzaService service) + { + _service = service; + } + + public void OnGet() + { + PizzaList = _service.GetPizzas(); + } + } +} diff --git a/WebUIWithRazor/Pages/Shared/_Layout.cshtml b/WebUIWithRazor/Pages/Shared/_Layout.cshtml index ff24a5c..d7071c9 100644 --- a/WebUIWithRazor/Pages/Shared/_Layout.cshtml +++ b/WebUIWithRazor/Pages/Shared/_Layout.cshtml @@ -22,6 +22,9 @@ + diff --git a/WebUIWithRazor/Program.cs b/WebUIWithRazor/Program.cs index 5c6dd50..c270441 100644 --- a/WebUIWithRazor/Program.cs +++ b/WebUIWithRazor/Program.cs @@ -10,6 +10,8 @@ builder.Services.AddRazorPages(); builder.Services.AddDbContext(options => options.UseSqlite("Data Source=ContosoPizza.db")); +builder.Services.AddScoped(); + var app = builder.Build(); // Configure the HTTP request pipeline.