Skip to content

Commit

Permalink
Display the list of pizzas
Browse files Browse the repository at this point in the history
  • Loading branch information
kathleenwest committed Oct 14, 2023
1 parent cdb82cd commit 98b1307
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ContosoPizza/Pages/PizzaList.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page
@using ContosoPizza.Models;
@model ContosoPizza.Pages.PizzaListModel
@{
ViewData["Title"] = "Pizza List 🍕";
Expand All @@ -8,3 +9,31 @@

<!-- New Pizza form will go here -->
<!-- List of pizzas will go here -->

<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 (Pizza 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-page-handler="Delete" asp-route-id="@pizza.Id">
<button class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
}
</tbody>
</table>
12 changes: 12 additions & 0 deletions ContosoPizza/Pages/PizzaList.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using ContosoPizza.Models;
using ContosoPizza.Services;

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();
}
}
}

0 comments on commit 98b1307

Please sign in to comment.