b465235096
page reloads.
89 lines
3.2 KiB
Plaintext
89 lines
3.2 KiB
Plaintext
@page "/students"
|
|
@attribute [Authorize]
|
|
@using Microsoft.EntityFrameworkCore
|
|
@using WebApp.Models
|
|
@inject AppDbContext Context
|
|
@inject IDialogService DialogService
|
|
@inject ISnackbar Snackbar
|
|
|
|
<PageTitle>Students - TSA Chapter Organizer</PageTitle>
|
|
|
|
<MudText Typo="Typo.h3">Students</MudText>
|
|
|
|
<MudButton StartIcon="@Icons.Material.Filled.Create" Href="students/create">Create New</MudButton>
|
|
<MudButton StartIcon="@AppIcons.EventRank" Href="students/event-ranking">Event Rankings</MudButton>
|
|
<MudButton StartIcon="@Icons.Material.Filled.AppRegistration" Href="students/teams">Registration</MudButton>
|
|
|
|
<MudDataGrid T="Student" ServerData="ServerReload" @ref="_dataGrid" Filterable="true" RowsPerPage="25">
|
|
<Columns>
|
|
<PropertyColumn Property="@(e => e.LastName)" Title="Name" Sortable="true">
|
|
<CellTemplate>
|
|
@context.Item.LastNameFirstName
|
|
@if (context.Item.OfficerRole != null)
|
|
{
|
|
<MudChip T="string" Icon="@(AppIcons.OfficerRoleIcon(context.Item.OfficerRole.Value))">@context.Item.OfficerRole</MudChip>
|
|
}
|
|
</CellTemplate>
|
|
</PropertyColumn>
|
|
<PropertyColumn Property="@(e => e.Grade)" Title="Grade (TSA Year)" Sortable="true">
|
|
<CellTemplate>
|
|
@context.Item.Grade (@context.Item.TsaYear)
|
|
</CellTemplate>
|
|
</PropertyColumn>
|
|
<TemplateColumn>
|
|
<CellTemplate>
|
|
<CrudActions DetailsHref="@($"/students/details?id={context.Item!.Id}&returnUrl=/students")"
|
|
EditHref="@($"/students/edit?id={context.Item!.Id}&returnUrl=/students")"
|
|
DeleteOnClick="() => DeleteStudent(context.Item!)">
|
|
</CrudActions>
|
|
</CellTemplate>
|
|
</TemplateColumn>
|
|
</Columns>
|
|
<PagerContent>
|
|
<MudDataGridPager T="Student"></MudDataGridPager>
|
|
</PagerContent>
|
|
</MudDataGrid>
|
|
|
|
@code {
|
|
MudDataGrid<Student> _dataGrid = null!;
|
|
|
|
private async Task<GridData<Student>> ServerReload(GridState<Student> state)
|
|
{
|
|
|
|
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
|
|
};
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|