Use PageHeader throughout the system
This commit is contained in:
@@ -1,21 +1,27 @@
|
||||
@page "/teams/edit"
|
||||
@attribute [Authorize]
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using WebApp.Components.Shared.Components
|
||||
@inject AppDbContext Context
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<PageTitle>Edit Team - TSA Chapter Organizer</PageTitle>
|
||||
|
||||
<MudText Typo="Typo.h3">Edit</MudText>
|
||||
<MudText Typo="Typo.h4">Team @(Team.ToString())</MudText>
|
||||
|
||||
@if (Team is null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
<EditForm method="post" Model="Team" OnValidSubmit="UpdateTeam" FormName="edit" Enhance>
|
||||
|
||||
<PageHeader Title="Edit Team"
|
||||
Subtitle=@Team.ToString()
|
||||
ShowBackButton="true"
|
||||
BackButtonUrl="/teams">
|
||||
<ActionButtons>
|
||||
<MudButton OnClick="UpdateTeam" Variant="Variant.Filled" Color="Color.Primary">Save</MudButton>
|
||||
<MudButton Href="/teams" Variant="Variant.Text">Cancel</MudButton>
|
||||
</ActionButtons>
|
||||
</PageHeader>
|
||||
|
||||
<EditForm method="post" Model="Team" OnValidSubmit="UpdateTeam" FormName="edit" Enhance>
|
||||
<AntiforgeryToken />
|
||||
<DataAnnotationsValidator/>
|
||||
<MudGrid>
|
||||
@@ -33,10 +39,7 @@ else
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
<MudButton StartIcon="@Icons.Material.Filled.ArrowBack" Href="teams">Back</MudButton>
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Save" OnClick="UpdateTeam">Save</MudButton>
|
||||
</EditForm>
|
||||
}
|
||||
</EditForm>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromQuery]
|
||||
@@ -45,7 +48,7 @@ else
|
||||
[SupplyParameterFromForm]
|
||||
private Team? Team { get; set; }
|
||||
|
||||
private IEnumerable<Student> _selectedStudents = [];
|
||||
private IEnumerable<Student>? _selectedStudents = [];
|
||||
private List<Student> _students = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
@@ -55,7 +58,7 @@ else
|
||||
.Include(e => e.Students)
|
||||
.FirstOrDefaultAsync(m => m.Id == Id);
|
||||
_students = await Context.Students.ToListAsync();
|
||||
_selectedStudents = Team.Students.ToList();
|
||||
_selectedStudents = Team?.Students.ToList();
|
||||
|
||||
if (Team is null)
|
||||
{
|
||||
@@ -68,6 +71,10 @@ else
|
||||
Team.Captain ??= Team.Students[0];
|
||||
Team.Identifier ??= Team.Captain.FirstName;
|
||||
break;
|
||||
case EventFormat.Team:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,14 +83,15 @@ else
|
||||
private async Task UpdateTeam()
|
||||
{
|
||||
//Context.Attach(Team!).Entity = EntityState.Modified;
|
||||
Team.Students.Clear();
|
||||
foreach (var s in _selectedStudents)
|
||||
{
|
||||
Team.Students.Add(s);
|
||||
}
|
||||
Team?.Students.Clear();
|
||||
if (_selectedStudents != null)
|
||||
foreach (var s in _selectedStudents)
|
||||
{
|
||||
Team?.Students.Add(s);
|
||||
}
|
||||
|
||||
// Update identifier for individual events
|
||||
if (Team.Event.EventFormat == EventFormat.Individual && Team.Students.Count == 1)
|
||||
if (Team is { Event.EventFormat: EventFormat.Individual, Students.Count: 1 })
|
||||
{
|
||||
Team.Captain ??= Team.Students[0];
|
||||
Team.Identifier = Team.Captain.FirstName;
|
||||
|
||||
Reference in New Issue
Block a user