Skip to content
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
Binary file modified ContosoPizza/ContosoPizza.db
Binary file not shown.
Binary file added ContosoPizza/ContosoPizza.db-shm
Binary file not shown.
Empty file.
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>
75 changes: 75 additions & 0 deletions ContosoPizza/Pages/PizzaList.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@page
@model ContosoPizza.Pages.PizzaListModel
@{
ViewData["Title"] = "Pizza List 🍕";
}

<h1>Pizza List: 🍕</h1>

<!-- New Pizza form will go here -->
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="NewPizza.Name" class="control-label"></label>
<input asp-for="NewPizza.Name" class="form-control" />
<span asp-validation-for="NewPizza.Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="NewPizza.Size" class="control-label"></label>
<select asp-for="NewPizza.Size" class="form-control" id="PizzaSize">
<option value="">-- Select Size --</option>
<option value="Small">Small</option>
<option value="Medium">Medium</option>
<option value="Large">Large</option>
</select>
<span asp-validation-for="NewPizza.Size" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="NewPizza.IsGlutenFree" /> @Html.DisplayNameFor(model =>
model.NewPizza.IsGlutenFree)
</label>
</div>
<div class="form-group">
<label asp-for="NewPizza.Price" class="control-label"></label>
<input asp-for="NewPizza.Price" class="form-control" />
<span asp-validation-for="NewPizza.Price" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>

<!-- 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>


@section Scripts {
<partial name="_ValidationScriptsPartial" />
}
48 changes: 48 additions & 0 deletions ContosoPizza/Pages/PizzaList.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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();
}

[BindProperty]
public Pizza NewPizza { get; set; } = default!;

public IActionResult OnPost()
{
if (!ModelState.IsValid || NewPizza == null)
{
return Page();
}

_service.AddPizza(NewPizza);

return RedirectToAction("Get");
}

public IActionResult OnPostDelete(int id)
{
_service.DeletePizza(id);

return RedirectToAction("Get");
}


}
}
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