@page "/tests"
@using Microsoft.EntityFrameworkCore
Tests
Tests
Add new
Name |
Abbreviation |
Synonyms |
@foreach (var test in Tests)
{
@test.Name
|
@test.Abbreviation
|
@(string.Join(", ", test.Synonyms.Select(x => x.Name).ToArray()))
|
}
@code {
[Inject]
public IDbContextFactory DbContextFactory { get; set; } = null!;
[Parameter]
[SupplyParameterFromQuery(Name = "page")]
public int? CurrentPage { get; set; }
private int Count { get; set; }
private int PageSize { get; set; } = 10;
private int TotalPages => (int)Math.Ceiling(decimal.Divide(Count, PageSize));
private List Tests { get; set; } = new();
private void Load()
{
using var ctx = DbContextFactory.CreateDbContext();
Count = ctx.Set().Count();
var page = CurrentPage ?? 1;
Tests = ctx.Set()
.OrderBy(x => x.Id)
.Skip((page - 1) * PageSize)
.Take(PageSize)
.Include(x => x.Synonyms)
.ToList();
}
protected override void OnInitialized()
{
base.OnInitialized();
Load();
}
protected override void OnParametersSet()
{
base.OnParametersSet();
Load();
}
}