Add Team functions
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
@page "/teams/delete"
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@inject AppDbContext context
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<PageTitle>Delete Team</PageTitle>
|
||||
|
||||
<h1>Delete</h1>
|
||||
|
||||
<p>Are you sure you want to delete this?</p>
|
||||
<div>
|
||||
<h2>Team</h2>
|
||||
<hr />
|
||||
@if (team is null)
|
||||
{
|
||||
<p><em>Loading...</em></p>
|
||||
}
|
||||
else {
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">Team</dt>
|
||||
<dd class="col-sm-10">@team.Event.Name</dd>
|
||||
</dl>
|
||||
<dl class="row">
|
||||
<dt class="col-sm-2">Students</dt>
|
||||
<dd class="col-sm-10">@string.Join(",", team.Students.Select(e => e.Name))</dd>
|
||||
</dl>
|
||||
|
||||
<EditForm method="post" Model="team" OnValidSubmit="DeleteTeam" FormName="delete" Enhance>
|
||||
<button type="submit" class="btn btn-danger" disabled="@(team is null)">Delete</button> |
|
||||
<a href="/teams">Back to List</a>
|
||||
</EditForm>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private Team? team;
|
||||
|
||||
[SupplyParameterFromQuery]
|
||||
private int Id { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
team = await context.Teams
|
||||
.Include(e => e.Event)
|
||||
.Include(e => e.Students)
|
||||
.FirstOrDefaultAsync(m => m.Id == Id);
|
||||
|
||||
if (team is null)
|
||||
{
|
||||
NavigationManager.NavigateTo("notfound");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteTeam()
|
||||
{
|
||||
context.Teams.Remove(team!);
|
||||
await context.SaveChangesAsync();
|
||||
NavigationManager.NavigateTo("/teams");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user