118 lines
4.8 KiB
Plaintext
118 lines
4.8 KiB
Plaintext
@page "/students"
|
|
@attribute [Authorize]
|
|
@using Microsoft.EntityFrameworkCore
|
|
@using WebApp.Models
|
|
@using WebApp.Components.Shared.Components
|
|
@inject AppDbContext Context
|
|
@inject IDialogService DialogService
|
|
@inject ISnackbar Snackbar
|
|
|
|
<PageHeader Title="Students">
|
|
<ActionButtons>
|
|
<MudButton StartIcon="@Icons.Material.Filled.Create" Href="students/create" Variant="Variant.Filled" Color="Color.Primary">Create New</MudButton>
|
|
<MudButton StartIcon="@AppIcons.EventRank" Href="students/event-ranking" Variant="Variant.Outlined">Event Rankings</MudButton>
|
|
<MudButton StartIcon="@AppIcons.Registration" Href="students/teams" Variant="Variant.Outlined">Registration</MudButton>
|
|
</ActionButtons>
|
|
</PageHeader>
|
|
|
|
<MudPaper Elevation="2" Class="pa-6">
|
|
<MudDataGrid T="Student"
|
|
ServerData="ServerReload"
|
|
@ref="_dataGrid"
|
|
Filterable="true"
|
|
RowsPerPage="25"
|
|
Dense="true"
|
|
Striped="true"
|
|
Hover="true"
|
|
Loading="@_isLoading"
|
|
LoadingProgressColor="Color.Primary">
|
|
<Columns>
|
|
<PropertyColumn Property="@(e => e.LastName)" Title="Name" Sortable="true">
|
|
<CellTemplate>
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Justify="Justify.SpaceBetween" Spacing="1">
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1">
|
|
<MudLink Href="@($"/students/details?id={context.Item.Id}&returnUrl=/students")"
|
|
Underline="Underline.Hover"
|
|
Color="Color.Primary">
|
|
@context.Item.LastNameFirstName
|
|
</MudLink>
|
|
@if (context.Item.OfficerRole != null)
|
|
{
|
|
<MudChip T="string" Size="Size.Small" Icon="@(AppIcons.OfficerRoleIcon(context.Item.OfficerRole.Value))">@context.Item.OfficerRole</MudChip>
|
|
}
|
|
</MudStack>
|
|
<MudStack Row="true" AlignItems="AlignItems.Center" Spacing="1">
|
|
<IconButtonWithTooltip Icon="@Icons.Material.Filled.Edit"
|
|
TooltipText="Edit"
|
|
Href="@($"/students/edit?id={context.Item.Id}&returnUrl=/students")" />
|
|
<IconButtonWithTooltip Icon="@Icons.Material.Outlined.Delete"
|
|
TooltipText="Delete"
|
|
HoverColor="Color.Error"
|
|
OnClick="() => DeleteStudent(context.Item!)" />
|
|
</MudStack>
|
|
</MudStack>
|
|
</CellTemplate>
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="@(e => e.Grade)" Title="Grade (TSA Year)" Sortable="true">
|
|
<CellTemplate>
|
|
@((MarkupString)AppIcons.GetOrdinalSuperscript(context.Item.Grade)) (@context.Item.TsaYear)
|
|
</CellTemplate>
|
|
</PropertyColumn>
|
|
</Columns>
|
|
<PagerContent>
|
|
<MudDataGridPager T="Student"></MudDataGridPager>
|
|
</PagerContent>
|
|
</MudDataGrid>
|
|
</MudPaper>
|
|
|
|
@code {
|
|
MudDataGrid<Student> _dataGrid = null!;
|
|
private bool _isLoading = true;
|
|
|
|
private async Task<GridData<Student>> ServerReload(GridState<Student> state)
|
|
{
|
|
_isLoading = true;
|
|
try
|
|
{
|
|
var query =
|
|
Context.Students.OrderBy(e => e.LastName)
|
|
.Where(state.FilterDefinitions).OrderBy(state.SortDefinitions);
|
|
|
|
var totalItems = await query.CountAsync();
|
|
var pagedData = await query.Skip(state.Page * state.PageSize).Take(state.PageSize).ToArrayAsync();
|
|
|
|
return new GridData<Student>
|
|
{
|
|
TotalItems = totalItems,
|
|
Items = pagedData
|
|
};
|
|
}
|
|
finally
|
|
{
|
|
_isLoading = false;
|
|
}
|
|
}
|
|
|
|
private async Task DeleteStudent(Student student)
|
|
{
|
|
//_isRowBlocked = true;
|
|
|
|
var result = await DialogService
|
|
.ShowMessageBox("Delete student",
|
|
(MarkupString)$"Are you sure want to delete <b>{student.Name}</b>? This cannot be undone.",
|
|
yesText:"Yes",
|
|
noText:"Cancel");
|
|
|
|
if (result == true)
|
|
{
|
|
Context.Students.Remove(student!);
|
|
await Context.SaveChangesAsync();
|
|
Snackbar.Add($"Delete event: Delete of Student {student.Name}", Severity.Info);
|
|
}
|
|
|
|
//_isRowBlocked = false;
|
|
StateHasChanged();
|
|
await _dataGrid.ReloadServerData();
|
|
}
|
|
}
|