@page "/teams/delete"
@using Microsoft.EntityFrameworkCore
@inject AppDbContext context
@inject NavigationManager NavigationManager
Delete Team
Delete
Are you sure you want to delete this?
Team
@if (team is null)
{
Loading...
}
else {
- Team
- @team.Event.Name
- Students
- @string.Join(",", team.Students.Select(e => e.Name))
|
Back to List
}
@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");
}
}