Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new page #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions ContosoPizza/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -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);
}

<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<h1 class="display-4">Welcome to Contoso Pizza</h1>
<p class="lead">
The best pizza in town for @Convert.ToInt32(timeInBusiness.TotalDays) days!
</p>
</div>
38 changes: 38 additions & 0 deletions ContosoPizza/Pages/PizzaList.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@page
@model ContosoPizza.Pages.PizzaListModel
@{
ViewData["Title"] = "Pizza List 🍕";
}

<h1>Pizza List 🍕</h1>

<!-- 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 (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-page-handler="Delete" asp-route-id="@pizza.Id">
<button class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
}
</tbody>
</table>
24 changes: 24 additions & 0 deletions ContosoPizza/Pages/PizzaList.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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();
}
}
}
10 changes: 8 additions & 2 deletions ContosoPizza/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand All @@ -8,13 +9,14 @@
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/ContosoPizza.styles.css" asp-append-version="true" />
</head>

<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">ContosoPizza</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
Expand All @@ -25,6 +27,9 @@
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/PizzaList">Pizza List 🍕</a>
</li>
</ul>
</div>
</div>
Expand All @@ -48,4 +53,5 @@

@await RenderSectionAsync("Scripts", required: false)
</body>

</html>
1 change: 1 addition & 0 deletions ContosoPizza/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddScoped<PizzaService>();
builder.Services.AddRazorPages();
builder.Services.AddDbContext<PizzaContext>(options =>
options.UseSqlite("Data Source=ContosoPizza.db"));
Expand Down