diff --git a/WebUIWithRazor/ContosoPizza.db-shm b/WebUIWithRazor/ContosoPizza.db-shm new file mode 100644 index 0000000..fe9ac28 Binary files /dev/null and b/WebUIWithRazor/ContosoPizza.db-shm differ diff --git a/WebUIWithRazor/ContosoPizza.db-wal b/WebUIWithRazor/ContosoPizza.db-wal new file mode 100644 index 0000000..e69de29 diff --git a/WebUIWithRazor/Pages/PizzaList.cshtml b/WebUIWithRazor/Pages/PizzaList.cshtml new file mode 100644 index 0000000..6925400 --- /dev/null +++ b/WebUIWithRazor/Pages/PizzaList.cshtml @@ -0,0 +1,35 @@ +@page +@model ContosoPizza.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) +
+ +
+
\ 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.