mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-04 13:57:37 +00:00
Initial commit
This commit is contained in:
parent
1d9d051759
commit
9656378279
557 changed files with 182300 additions and 0 deletions
21
vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj
Normal file
21
vscode/PracticalApps/Northwind.Web/Northwind.Web.csproj
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<!--remove the element below after GA release-->
|
||||
<LangVersion>preview</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Console" Static="true" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- change Sqlite to SqlServer if you prefer -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
|
||||
<ProjectReference Include="..\Northwind.Razor.Employees\Northwind.Razor.Employees.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
13
vscode/PracticalApps/Northwind.Web/Pages/Orders.cshtml
Normal file
13
vscode/PracticalApps/Northwind.Web/Pages/Orders.cshtml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
@page
|
||||
@using Packt.Shared
|
||||
@inject NorthwindContext db
|
||||
@{
|
||||
string title = "Orders";
|
||||
ViewData["Title"] = $"Northwind B2B - {title}";
|
||||
}
|
||||
<div class="row">
|
||||
<h1 class="display-2">@title</h1>
|
||||
<p>
|
||||
There are @db.Orders.Count() orders in the Northwind database.
|
||||
</p>
|
||||
</div>
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content=
|
||||
"width=device-width, initial-scale=1, shrink-to-fit=no" />
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href=
|
||||
"https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
<title>@ViewData["Title"]</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
@RenderBody()
|
||||
<hr />
|
||||
<footer>
|
||||
<p>Copyright © 2022 - @ViewData["Title"]</p>
|
||||
</footer>
|
||||
</div>
|
||||
<!-- JavaScript to enable features like carousel -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
|
||||
@RenderSection("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
42
vscode/PracticalApps/Northwind.Web/Pages/Suppliers.cshtml
Normal file
42
vscode/PracticalApps/Northwind.Web/Pages/Suppliers.cshtml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
@page
|
||||
@using Packt.Shared
|
||||
@model Northwind.Web.Pages.SuppliersModel
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
<div class="row">
|
||||
<h1 class="display-2">Suppliers</h1>
|
||||
<table class="table">
|
||||
<thead class="thead-inverse">
|
||||
<tr>
|
||||
<th>Company Name</th>
|
||||
<th>Country</th>
|
||||
<th>Phone</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if (Model.Suppliers is not null)
|
||||
{
|
||||
@foreach(Supplier s in Model.Suppliers)
|
||||
{
|
||||
<tr>
|
||||
<td>@s.CompanyName</td>
|
||||
<td>@s.Country</td>
|
||||
<td>@s.Phone</td>
|
||||
</tr>
|
||||
}
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="row">
|
||||
<p>Enter details for a new supplier:</p>
|
||||
<form method="POST">
|
||||
<div><input asp-for="Supplier.CompanyName"
|
||||
placeholder="Company Name" /></div>
|
||||
<div><input asp-for="Supplier.Country"
|
||||
placeholder="Country" /></div>
|
||||
<div><input asp-for="Supplier.Phone"
|
||||
placeholder="Phone" /></div>
|
||||
<input type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
42
vscode/PracticalApps/Northwind.Web/Pages/Suppliers.cshtml.cs
Normal file
42
vscode/PracticalApps/Northwind.Web/Pages/Suppliers.cshtml.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using Microsoft.AspNetCore.Mvc.RazorPages; // PageModel
|
||||
using Packt.Shared; // NorthwindContext
|
||||
using Microsoft.AspNetCore.Mvc; // [BindProperty], IActionResult
|
||||
|
||||
namespace Northwind.Web.Pages;
|
||||
|
||||
public class SuppliersModel : PageModel
|
||||
{
|
||||
private NorthwindContext db;
|
||||
|
||||
public SuppliersModel(NorthwindContext injectedContext)
|
||||
{
|
||||
db = injectedContext;
|
||||
}
|
||||
|
||||
public IEnumerable<Supplier>? Suppliers { get; set; }
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
ViewData["Title"] = "Northwind B2B - Suppliers";
|
||||
|
||||
Suppliers = db.Suppliers
|
||||
.OrderBy(c => c.Country).ThenBy(c => c.CompanyName);
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public Supplier? Supplier { get; set; }
|
||||
|
||||
public IActionResult OnPost()
|
||||
{
|
||||
if ((Supplier is not null) && ModelState.IsValid)
|
||||
{
|
||||
db.Suppliers.Add(Supplier);
|
||||
db.SaveChanges();
|
||||
return RedirectToPage("/suppliers");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Page(); // return to original page
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
28
vscode/PracticalApps/Northwind.Web/Pages/index.cshtml
Normal file
28
vscode/PracticalApps/Northwind.Web/Pages/index.cshtml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
@page
|
||||
@functions
|
||||
{
|
||||
public string? DayName { get; set; }
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
ViewData["Title"] = "Northwind B2B";
|
||||
Model.DayName = DateTime.Now.ToString("dddd");
|
||||
}
|
||||
}
|
||||
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-3">Welcome to Northwind B2B</h1>
|
||||
<p class="lead">We supply products to our customers.</p>
|
||||
<hr />
|
||||
<p>It's @Model.DayName! Our customers include restaurants, hotels, and cruise lines.</p>
|
||||
<p>
|
||||
<a class="btn btn-primary" href="suppliers">
|
||||
Learn more about our suppliers
|
||||
</a>
|
||||
</p>
|
||||
<p>
|
||||
<a class="btn btn-primary" href="packtfeatures/employees">
|
||||
Contact our employees
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
53
vscode/PracticalApps/Northwind.Web/Program.cs
Normal file
53
vscode/PracticalApps/Northwind.Web/Program.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using Packt.Shared; // AddNorthwindContext extension method
|
||||
|
||||
// configure services
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Services.AddRazorPages();
|
||||
builder.Services.AddNorthwindContext();
|
||||
var app = builder.Build();
|
||||
|
||||
// configure the HTTP pipeline
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.Use(async (HttpContext context, Func<Task> next) =>
|
||||
{
|
||||
RouteEndpoint? rep = context.GetEndpoint() as RouteEndpoint;
|
||||
|
||||
if (rep is not null)
|
||||
{
|
||||
WriteLine($"Endpoint name: {rep.DisplayName}");
|
||||
WriteLine($"Endpoint route pattern: {rep.RoutePattern.RawText}");
|
||||
}
|
||||
|
||||
if (context.Request.Path == "/bonjour")
|
||||
{
|
||||
// in the case of a match on URL path, this becomes a terminating
|
||||
// delegate that returns so does not call the next delegate
|
||||
await context.Response.WriteAsync("Bonjour Monde!");
|
||||
return;
|
||||
}
|
||||
|
||||
// we could modify the request before calling the next delegate
|
||||
await next();
|
||||
|
||||
// we could modify the response after calling the next delegate
|
||||
});
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseDefaultFiles(); // index.html, default.html, and so on
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.MapRazorPages();
|
||||
app.MapGet("/hello", () => "Hello World!");
|
||||
|
||||
// start the web server
|
||||
|
||||
app.Run();
|
||||
|
||||
WriteLine("This executes after the web server has stopped!");
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:55055",
|
||||
"sslPort": 44382
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"Northwind.Web": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"applicationUrl": "https://localhost:5001;http://localhost:5000",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
vscode/PracticalApps/Northwind.Web/appsettings.json
Normal file
9
vscode/PracticalApps/Northwind.Web/appsettings.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
26
vscode/PracticalApps/Northwind.Web/wwwroot/index.html
Normal file
26
vscode/PracticalApps/Northwind.Web/wwwroot/index.html
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1 " />
|
||||
<!-- Bootstrap CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
|
||||
<title>Welcome ASP.NET Core!</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-3">Welcome to Northwind B2B</h1>
|
||||
<p class="lead">We supply products to our customers.</p>
|
||||
<hr />
|
||||
<h2>This is a static HTML page.</h2>
|
||||
<p>Our customers include restaurants, hotels, and cruise lines.</p>
|
||||
<p>
|
||||
<a class="btn btn-primary"
|
||||
href="https://www.asp.net/">Learn more</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue