1
This commit is contained in:
19
BlazorApp1/Components/Pages/Counter.razor
Normal file
19
BlazorApp1/Components/Pages/Counter.razor
Normal file
@@ -0,0 +1,19 @@
|
||||
@page "/counter"
|
||||
@rendermode InteractiveServer
|
||||
|
||||
<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++;
|
||||
}
|
||||
}
|
||||
36
BlazorApp1/Components/Pages/Error.razor
Normal file
36
BlazorApp1/Components/Pages/Error.razor
Normal file
@@ -0,0 +1,36 @@
|
||||
@page "/Error"
|
||||
@using System.Diagnostics
|
||||
|
||||
<PageTitle>Error</PageTitle>
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to <strong>Development</strong> environment will display more 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>
|
||||
|
||||
@code{
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
private string? RequestId { get; set; }
|
||||
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
|
||||
protected override void OnInitialized() =>
|
||||
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
|
||||
}
|
||||
7
BlazorApp1/Components/Pages/Home.razor
Normal file
7
BlazorApp1/Components/Pages/Home.razor
Normal file
@@ -0,0 +1,7 @@
|
||||
@page "/"
|
||||
|
||||
<PageTitle>Home</PageTitle>
|
||||
|
||||
<h1>Hello, world!</h1>
|
||||
|
||||
Welcome to your new app.
|
||||
54
BlazorApp1/Components/Pages/LotteryTicketPages/Create.razor
Normal file
54
BlazorApp1/Components/Pages/LotteryTicketPages/Create.razor
Normal file
@@ -0,0 +1,54 @@
|
||||
@page "/lotterytickets/create"
|
||||
@inject BlazorApp1.Data.BlazorApp1Context DB
|
||||
@using Services.Tickets.Models
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<PageTitle>Create</PageTitle>
|
||||
|
||||
<h1>Create</h1>
|
||||
|
||||
<h4>LotteryTicket</h4>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
@* <EditForm method="post" Model="LotteryTicket" OnValidSubmit="AddLotteryTicket" FormName="create" Enhance>
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary class="text-danger" />
|
||||
<div class="mb-3">
|
||||
<label for="numbers" class="form-label">Numbers:</label>
|
||||
<InputText id="numbers" @bind-Value="LotteryTicket.Numbers" class="form-control" />
|
||||
<ValidationMessage For="() => LotteryTicket.Numbers" class="text-danger" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="owner" class="form-label">Owner:</label>
|
||||
<InputText id="owner" @bind-Value="LotteryTicket.Owner" class="form-control" />
|
||||
<ValidationMessage For="() => LotteryTicket.Owner" class="text-danger" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phonenumber" class="form-label">PhoneNumber:</label>
|
||||
<InputText id="phonenumber" @bind-Value="LotteryTicket.PhoneNumber" class="form-control" />
|
||||
<ValidationMessage For="() => LotteryTicket.PhoneNumber" class="text-danger" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Create</button>
|
||||
</EditForm>
|
||||
*@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="/lotterytickets">Back to List</a>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
public LotteryTicket LotteryTicket { get; set; } = new();
|
||||
|
||||
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
|
||||
public async Task AddLotteryTicket()
|
||||
{
|
||||
DB.LotteryTicket.Add(LotteryTicket);
|
||||
await DB.SaveChangesAsync();
|
||||
NavigationManager.NavigateTo("/lotterytickets");
|
||||
}
|
||||
}
|
||||
61
BlazorApp1/Components/Pages/LotteryTicketPages/Delete.razor
Normal file
61
BlazorApp1/Components/Pages/LotteryTicketPages/Delete.razor
Normal file
@@ -0,0 +1,61 @@
|
||||
@page "/lotterytickets/delete"
|
||||
@inject BlazorApp1.Data.BlazorApp1Context DB
|
||||
@using Services.Tickets.Models
|
||||
@inject NavigationManager NavigationManager
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
|
||||
<PageTitle>Delete</PageTitle>
|
||||
|
||||
<h1>Delete</h1>
|
||||
|
||||
<h3>Are you sure you want to delete this?</h3>
|
||||
<div>
|
||||
<h4>LotteryTicket</h4>
|
||||
<hr />
|
||||
@if (lotteryticket is null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else {
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">Numbers</dt>
|
||||
<dd class="col-sm-10">@lotteryticket.Numbers</dd>
|
||||
</dl>
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">Owner</dt>
|
||||
<dd class="col-sm-10">@lotteryticket.Owner</dd>
|
||||
</dl>
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">PhoneNumber</dt>
|
||||
<dd class="col-sm-10">@lotteryticket.PhoneNumber</dd>
|
||||
</dl>
|
||||
<EditForm method="post" Model="lotteryticket" OnValidSubmit="DeleteLotteryTicket" FormName="delete" Enhance>
|
||||
<button type="submit" class="btn btn-danger" disabled="@(lotteryticket is null)">Delete</button> |
|
||||
<a href="/lotterytickets">Back to List</a>
|
||||
</EditForm>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
LotteryTicket? lotteryticket;
|
||||
|
||||
[SupplyParameterFromQuery]
|
||||
public long? Id { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
lotteryticket = await DB.LotteryTicket.FirstOrDefaultAsync(m => m.Id == Id);
|
||||
|
||||
if (lotteryticket is null)
|
||||
{
|
||||
NavigationManager.NavigateTo("notfound");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteLotteryTicket()
|
||||
{
|
||||
DB.LotteryTicket.Remove(lotteryticket!);
|
||||
await DB.SaveChangesAsync();
|
||||
NavigationManager.NavigateTo("/lotterytickets");
|
||||
}
|
||||
}
|
||||
49
BlazorApp1/Components/Pages/LotteryTicketPages/Details.razor
Normal file
49
BlazorApp1/Components/Pages/LotteryTicketPages/Details.razor
Normal file
@@ -0,0 +1,49 @@
|
||||
@page "/lotterytickets/details"
|
||||
@inject BlazorApp1.Data.BlazorApp1Context DB
|
||||
@using Services.Tickets.Models
|
||||
@inject NavigationManager NavigationManager
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
|
||||
<PageTitle>Details</PageTitle>
|
||||
|
||||
<h1>Details</h1>
|
||||
|
||||
<div>
|
||||
<h4>LotteryTicket</h4>
|
||||
<hr />
|
||||
@if (lotteryticket is null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else {
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">Numbers</dt>
|
||||
<dd class="col-sm-10">@lotteryticket.Numbers</dd>
|
||||
<dt class="col-sm-2">Owner</dt>
|
||||
<dd class="col-sm-10">@lotteryticket.Owner</dd>
|
||||
<dt class="col-sm-2">PhoneNumber</dt>
|
||||
<dd class="col-sm-10">@lotteryticket.PhoneNumber</dd>
|
||||
</dl>
|
||||
<div>
|
||||
<a href="@($"/lotterytickets/edit?id={lotteryticket.Id}")">Edit</a> |
|
||||
<a href="@($"/lotterytickets")">Back to List</a>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
LotteryTicket? lotteryticket;
|
||||
|
||||
[SupplyParameterFromQuery]
|
||||
public long? Id { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
lotteryticket = await DB.LotteryTicket.FirstOrDefaultAsync(m => m.Id == Id);
|
||||
|
||||
if (lotteryticket is null)
|
||||
{
|
||||
NavigationManager.NavigateTo("notfound");
|
||||
}
|
||||
}
|
||||
}
|
||||
96
BlazorApp1/Components/Pages/LotteryTicketPages/Edit.razor
Normal file
96
BlazorApp1/Components/Pages/LotteryTicketPages/Edit.razor
Normal file
@@ -0,0 +1,96 @@
|
||||
@page "/LotteryTickets/edit"
|
||||
@inject BlazorApp1.Data.BlazorApp1Context DB
|
||||
@using Services.Tickets.Models
|
||||
@inject NavigationManager NavigationManager
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
|
||||
<PageTitle>Edit</PageTitle>
|
||||
|
||||
<h1>Edit</h1>
|
||||
|
||||
<h4>LotteryTicket</h4>
|
||||
<hr />
|
||||
@if (LotteryTicket is null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<EditForm method="post" Model="LotteryTicket" OnValidSubmit="UpdateLotteryTicket" FormName="edit" Enhance>
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
<input type="hidden" name="LotteryTicket.Id" value="@LotteryTicket.Id" />
|
||||
<div class="mb-3">
|
||||
<label for="numbers" class="form-label">Numbers:</label>
|
||||
<InputText id="numbers" @bind-Value="LotteryTicket.Numbers" class="form-control" />
|
||||
<ValidationMessage For="() => LotteryTicket.Numbers" class="text-danger" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="owner" class="form-label">Owner:</label>
|
||||
<InputText id="owner" @bind-Value="LotteryTicket.Owner" class="form-control" />
|
||||
<ValidationMessage For="() => LotteryTicket.Owner" class="text-danger" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="phonenumber" class="form-label">PhoneNumber:</label>
|
||||
<InputText id="phonenumber" @bind-Value="LotteryTicket.PhoneNumber" class="form-control" />
|
||||
<ValidationMessage For="() => LotteryTicket.PhoneNumber" class="text-danger" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</EditForm>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div>
|
||||
<a href="/lotterytickets">Back to List</a>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromQuery]
|
||||
public long? Id { get; set; }
|
||||
|
||||
[SupplyParameterFromForm]
|
||||
public LotteryTicket? LotteryTicket { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
LotteryTicket ??= await DB.LotteryTicket.FirstOrDefaultAsync(m => m.Id == Id);
|
||||
|
||||
if (LotteryTicket is null)
|
||||
{
|
||||
NavigationManager.NavigateTo("notfound");
|
||||
}
|
||||
}
|
||||
|
||||
// To protect from overposting attacks, enable the specific properties you want to bind to.
|
||||
// For more details, see https://aka.ms/RazorPagesCRUD.
|
||||
public async Task UpdateLotteryTicket()
|
||||
{
|
||||
DB.Attach(LotteryTicket!).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await DB.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!LotteryTicketExists(LotteryTicket!.Id))
|
||||
{
|
||||
NavigationManager.NavigateTo("notfound");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
NavigationManager.NavigateTo("/lotterytickets");
|
||||
}
|
||||
|
||||
bool LotteryTicketExists(long? id)
|
||||
{
|
||||
return DB.LotteryTicket.Any(e => e.Id == id);
|
||||
}
|
||||
}
|
||||
24
BlazorApp1/Components/Pages/LotteryTicketPages/Index.razor
Normal file
24
BlazorApp1/Components/Pages/LotteryTicketPages/Index.razor
Normal file
@@ -0,0 +1,24 @@
|
||||
@page "/lotterytickets"
|
||||
@using Microsoft.AspNetCore.Components.QuickGrid
|
||||
@inject BlazorApp1.Data.BlazorApp1Context DB
|
||||
@using Services.Tickets.Models
|
||||
|
||||
<PageTitle>Index</PageTitle>
|
||||
|
||||
<h1>Index</h1>
|
||||
|
||||
<p>
|
||||
<a href="lotterytickets/create">Create New</a>
|
||||
</p>
|
||||
|
||||
<QuickGrid Class="table" Items="DB.LotteryTicket">
|
||||
<PropertyColumn Property="lotteryticket => lotteryticket.Numbers" />
|
||||
<PropertyColumn Property="lotteryticket => lotteryticket.Owner" />
|
||||
<PropertyColumn Property="lotteryticket => lotteryticket.PhoneNumber" />
|
||||
|
||||
<TemplateColumn Context="lotteryticket">
|
||||
<a href="@($"lotterytickets/edit?id={lotteryticket.Id}")">Edit</a> |
|
||||
<a href="@($"lotterytickets/details?id={lotteryticket.Id}")">Details</a> |
|
||||
<a href="@($"lotterytickets/delete?id={lotteryticket.Id}")">Delete</a>
|
||||
</TemplateColumn>
|
||||
</QuickGrid>
|
||||
64
BlazorApp1/Components/Pages/Weather.razor
Normal file
64
BlazorApp1/Components/Pages/Weather.razor
Normal file
@@ -0,0 +1,64 @@
|
||||
@page "/weather"
|
||||
@attribute [StreamRendering]
|
||||
|
||||
<PageTitle>Weather</PageTitle>
|
||||
|
||||
<h1>Weather</h1>
|
||||
|
||||
<p>This component demonstrates showing data.</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()
|
||||
{
|
||||
// Simulate asynchronous loading to demonstrate streaming rendering
|
||||
await Task.Delay(500);
|
||||
|
||||
var startDate = DateOnly.FromDateTime(DateTime.Now);
|
||||
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
|
||||
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = startDate.AddDays(index),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = summaries[Random.Shared.Next(summaries.Length)]
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
private class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
public int TemperatureC { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user