@page "/LotteryTickets/edit"
@inject BlazorApp1.Data.BlazorApp1Context DB
@using Services.Tickets.Models
@inject NavigationManager NavigationManager
@using Microsoft.EntityFrameworkCore
Edit
Edit
LotteryTicket
@if (LotteryTicket is null)
{
Loading...
}
else
{
}
@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);
}
}