2
This commit is contained in:
@@ -1,96 +1 @@
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user