@page "/events/edit" @attribute [Authorize] @using Microsoft.EntityFrameworkCore @inject AppDbContext context @inject NavigationManager NavigationManager Edit Event - TSA Chapter Organizer Edit Event Format @foreach (EventFormat format in Enum.GetValues(typeof(EventFormat))) { @format.ToString() } Back Save @code { [SupplyParameterFromQuery] private int Id { get; set; } [SupplyParameterFromForm] private EventDefinition? EventDefinition { get; set; } protected override async Task OnInitializedAsync() { EventDefinition ??= await context.Events.FirstOrDefaultAsync(m => m.Id == Id); if (EventDefinition is null) { NavigationManager.NavigateTo("notfound"); } } // To protect from overposting attacks, enable the specific properties you want to bind to. // For more information, see https://learn.microsoft.com/aspnet/core/blazor/forms/#mitigate-overposting-attacks. private void OnValidSubmit() { context.Attach(EventDefinition!).State = EntityState.Modified; try { context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EventDefinitionExists(EventDefinition!.Id)) { NavigationManager.NavigateTo("notfound"); } else { throw; } } NavigationManager.NavigateTo("/events"); } private bool EventDefinitionExists(int id) { return context.Events.Any(e => e.Id == id); } }