add pizza list page

main
Peace 11 months ago
parent 2a64a14eb2
commit 38a0af9925
  1. BIN
      WebUIWithRazor/ContosoPizza.db-shm
  2. 0
      WebUIWithRazor/ContosoPizza.db-wal
  3. 35
      WebUIWithRazor/Pages/PizzaList.cshtml
  4. 23
      WebUIWithRazor/Pages/PizzaList.cshtml.cs
  5. 3
      WebUIWithRazor/Pages/Shared/_Layout.cshtml
  6. 2
      WebUIWithRazor/Program.cs

@ -0,0 +1,35 @@
@page
@model ContosoPizza.Pages.PizzaListModel
@{
ViewData["Title"] = "Pizza List 🍕";
}
<h1>Pizza List 🍕</h1>
<table class="table mt-5">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Price</th>
<th scope="col">Size</th>
<th scope="col">Gluten Free</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
@foreach (var pizza in Model.PizzaList)
{
<tr>
<td>@pizza.Name</td>
<td>@($"{pizza.Price:C}")</td>
<td>@pizza.Size</td>
<td>@(pizza.IsGlutenFree ? "✔" : string.Empty)</td>
<td>
<form method="post" asp-asp-page-handler="Delete" asp-route-id="@pizza.Id">
<button class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
}
</tbody>
</table>

@ -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<Pizza> PizzaList { get; set; } = default;
public PizzaListModel(PizzaService service)
{
_service = service;
}
public void OnGet()
{
PizzaList = _service.GetPizzas();
}
}
}

@ -22,6 +22,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/PizzaList">Pizza List 🍕</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>

@ -10,6 +10,8 @@ builder.Services.AddRazorPages();
builder.Services.AddDbContext<PizzaContext>(options =>
options.UseSqlite("Data Source=ContosoPizza.db"));
builder.Services.AddScoped<PizzaService>();
var app = builder.Build();
// Configure the HTTP request pipeline.

Loading…
Cancel
Save