mirror of
https://github.com/markjprice/cs11dotnet7.git
synced 2026-04-21 06:03:57 +00:00
Initial commit
This commit is contained in:
parent
1d9d051759
commit
9656378279
557 changed files with 182300 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
@page "/counter"
|
||||
|
||||
<PageTitle>Counter</PageTitle>
|
||||
|
||||
<h1>Counter</h1>
|
||||
|
||||
<p role="status">Current count: @currentCount</p>
|
||||
|
||||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
|
||||
|
||||
@code {
|
||||
private int currentCount = 0;
|
||||
|
||||
private void IncrementCount()
|
||||
{
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
@page "/createcustomer"
|
||||
@inject INorthwindService service
|
||||
@inject NavigationManager navigation
|
||||
|
||||
<h3>Create Customer</h3>
|
||||
|
||||
<CustomerDetail ButtonText="Create Customer"
|
||||
Customer="@customer"
|
||||
OnValidSubmit="@Create" />
|
||||
|
||||
@code {
|
||||
private Customer customer = new();
|
||||
|
||||
private async Task Create()
|
||||
{
|
||||
await service.CreateCustomerAsync(customer);
|
||||
navigation.NavigateTo("customers");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
@using Microsoft.EntityFrameworkCore @* ToListAsync extension method *@
|
||||
@page "/customers/{country?}"
|
||||
@inject INorthwindService service
|
||||
|
||||
<h3>
|
||||
Customers @(string.IsNullOrWhiteSpace(Country)
|
||||
? "Worldwide" : "in " + Country)
|
||||
</h3>
|
||||
|
||||
<div class="form-group">
|
||||
<a class="btn btn-info" href="createcustomer">
|
||||
<i class="oi oi-plus"></i> Create New</a>
|
||||
</div>
|
||||
|
||||
@if (customers is null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Id</th>
|
||||
<th>Company Name</th>
|
||||
<th>Address</th>
|
||||
<th>Phone</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (Customer c in customers)
|
||||
{
|
||||
<tr>
|
||||
<td>@c.CustomerId</td>
|
||||
<td>@c.CompanyName</td>
|
||||
<td>
|
||||
@c.Address<br />
|
||||
@c.City<br />
|
||||
@c.PostalCode<br />
|
||||
@c.Country
|
||||
</td>
|
||||
<td>@c.Phone</td>
|
||||
<td>
|
||||
<a class="btn btn-info" href="editcustomer/@c.CustomerId">
|
||||
<i class="oi oi-pencil"></i>
|
||||
</a>
|
||||
<a class="btn btn-danger"
|
||||
href="deletecustomer/@c.CustomerId">
|
||||
<i class="oi oi-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? Country { get; set; }
|
||||
|
||||
private IEnumerable<Customer>? customers;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Country))
|
||||
{
|
||||
customers = await service.GetCustomersAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
customers = await service.GetCustomersAsync(Country);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
@page "/deletecustomer/{customerid}"
|
||||
@inject INorthwindService service
|
||||
@inject NavigationManager navigation
|
||||
|
||||
<h3>Delete Customer</h3>
|
||||
|
||||
<div class="alert alert-danger">
|
||||
Warning! This action cannot be undone!
|
||||
</div>
|
||||
|
||||
<CustomerDetail ButtonText="Delete Customer"
|
||||
ButtonStyle="danger"
|
||||
Customer="@customer"
|
||||
OnValidSubmit="@Delete" />
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string CustomerId { get; set; } = null!;
|
||||
|
||||
private Customer? customer = new();
|
||||
|
||||
protected async override Task OnParametersSetAsync()
|
||||
{
|
||||
customer = await service.GetCustomerAsync(CustomerId);
|
||||
}
|
||||
|
||||
private async Task Delete()
|
||||
{
|
||||
if (customer is not null)
|
||||
{
|
||||
await service.DeleteCustomerAsync(CustomerId);
|
||||
}
|
||||
|
||||
navigation.NavigateTo("customers");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
@page "/editcustomer/{customerid}"
|
||||
@inject INorthwindService service
|
||||
@inject NavigationManager navigation
|
||||
|
||||
<h3>Edit Customer</h3>
|
||||
|
||||
<CustomerDetail ButtonText="Update"
|
||||
Customer="@customer"
|
||||
OnValidSubmit="@Update" />
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string CustomerId { get; set; } = null!;
|
||||
|
||||
private Customer? customer = new();
|
||||
|
||||
protected async override Task OnParametersSetAsync()
|
||||
{
|
||||
customer = await service.GetCustomerAsync(CustomerId);
|
||||
}
|
||||
|
||||
private async Task Update()
|
||||
{
|
||||
if (customer is not null)
|
||||
{
|
||||
await service.UpdateCustomerAsync(customer);
|
||||
}
|
||||
|
||||
navigation.NavigateTo("customers");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
@page
|
||||
@model Northwind.BlazorServer.Pages.ErrorModel
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<title>Error</title>
|
||||
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="main">
|
||||
<div class="content px-4">
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Northwind.BlazorServer.Pages
|
||||
{
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[IgnoreAntiforgeryToken]
|
||||
public class ErrorModel : PageModel
|
||||
{
|
||||
public string? RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
private readonly ILogger<ErrorModel> _logger;
|
||||
|
||||
public ErrorModel(ILogger<ErrorModel> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void OnGet()
|
||||
{
|
||||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
@page "/fetchdata"
|
||||
|
||||
<PageTitle>Weather forecast</PageTitle>
|
||||
|
||||
@using Northwind.BlazorServer.Data
|
||||
@inject WeatherForecastService ForecastService
|
||||
|
||||
<h1>Weather forecast</h1>
|
||||
|
||||
<p>This component demonstrates fetching data from a service.</p>
|
||||
|
||||
@if (forecasts == null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Temp. (C)</th>
|
||||
<th>Temp. (F)</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var forecast in forecasts)
|
||||
{
|
||||
<tr>
|
||||
<td>@forecast.Date.ToShortDateString()</td>
|
||||
<td>@forecast.TemperatureC</td>
|
||||
<td>@forecast.TemperatureF</td>
|
||||
<td>@forecast.Summary</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
|
||||
@code {
|
||||
private WeatherForecast[]? forecasts;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
@page "/"
|
||||
|
||||
<PageTitle>Index</PageTitle>
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
|
||||
<SurveyPrompt Title="How is Blazor working for you?" />
|
||||
|
||||
<button type="button" class="btn btn-info" @onclick="AlertBrowser">
|
||||
Poke the browser</button>
|
||||
<hr />
|
||||
<input id="colorBox" />
|
||||
<button type="button" class="btn btn-info" @onclick="SetColor">
|
||||
Set Color</button>
|
||||
<button type="button" class="btn btn-info" @onclick="GetColor">
|
||||
Get Color</button>
|
||||
|
||||
@code {
|
||||
[Inject]
|
||||
public IJSRuntime JSRuntime { get; set; } = null!;
|
||||
|
||||
public async Task AlertBrowser()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync(
|
||||
"messageBox", "Blazor poking the browser");
|
||||
}
|
||||
|
||||
public async Task SetColor()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("setColorInStorage");
|
||||
}
|
||||
|
||||
public async Task GetColor()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("getColorFromStorage");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
@page "/"
|
||||
@namespace Northwind.BlazorServer.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
|
||||
<component type="typeof(App)" render-mode="ServerPrerendered" />
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
@using Microsoft.AspNetCore.Components.Web
|
||||
@namespace Northwind.BlazorServer.Pages
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<base href="~/" />
|
||||
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
|
||||
<link href="css/site.css" rel="stylesheet" />
|
||||
<link href="Northwind.BlazorServer.styles.css" rel="stylesheet" />
|
||||
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
|
||||
</head>
|
||||
<body>
|
||||
@RenderBody()
|
||||
|
||||
<div id="blazor-error-ui">
|
||||
<environment include="Staging,Production">
|
||||
An error has occurred. This application may no longer respond until reloaded.
|
||||
</environment>
|
||||
<environment include="Development">
|
||||
An unhandled exception has occurred. See browser dev tools for details.
|
||||
</environment>
|
||||
<a href="" class="reload">Reload</a>
|
||||
<a class="dismiss">🗙</a>
|
||||
</div>
|
||||
|
||||
<script src="_framework/blazor.server.js"></script>
|
||||
<script src="scripts/interop.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue