@page "/labs"
@using Microsoft.EntityFrameworkCore
Labs
Labs
Add new
Name |
Location |
@foreach (var lab in Labs)
{
@lab.Name
|
@if (!string.IsNullOrEmpty(lab.AddressCity))
{
@lab.AddressCity@(", ")
}
@lab.Country.Name
|
}
@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 Labs { get; set; } = new();
private void Load()
{
using var ctx = DbContextFactory.CreateDbContext();
Count = ctx.Set().Count();
var page = CurrentPage ?? 1;
Labs = ctx.Set()
.OrderBy(x => x.Id)
.Skip((page - 1) * PageSize)
.Take(PageSize)
.Include(x => x.Country)
.ToList();
}
protected override void OnInitialized()
{
base.OnInitialized();
Load();
}
protected override void OnParametersSet()
{
base.OnParametersSet();
Load();
}
}