Refactor Audit service and view: implement GetCount and LoadPage methods, update OnReadData for improved data handling

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
a.beging@eas-solutions.de
2026-04-29 15:35:47 +02:00
parent c0c18f2ddd
commit 87f26f9367
3 changed files with 74 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
using Blazorise.DataGrid;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Server.Data.Service;
using Microsoft.AspNetCore.Components;
@@ -26,16 +27,44 @@ namespace FoodsharingSiegen.Server.Pages
/// </summary>
private List<Audit>? Audits { get; set; }
/// <summary>
/// Gets or sets the value of the total audits (ab)
/// </summary>
private int TotalAudits { get; set; }
#endregion
#region Override InitializeDataAsync
/// <inheritdoc />
protected override async Task InitializeDataAsync()
protected override Task InitializeDataAsync()
{
var loadR = await AuditService?.Load(100)!;
if (loadR.Success)
Audits = loadR.Data;
return Task.CompletedTask;
}
#endregion
#region Private Method OnReadData
/// <summary>
/// Called when data is read (ab)
/// </summary>
/// <param name="e">The params</param>
private async Task OnReadData(DataGridReadDataEventArgs<Audit> e)
{
var countLoad = await AuditService?.GetCount()!;
if (countLoad.Success)
TotalAudits = countLoad.Data;
// Default fallback if VirtualizeCount is not set, though Blazor shouldn't do this usually
var limit = e.VirtualizeCount > 0 ? e.VirtualizeCount : 50;
var offset = e.VirtualizeOffset;
var itemsLoad = await AuditService?.LoadPage(offset, limit)!;
if (itemsLoad.Success)
Audits = itemsLoad.Data;
await InvokeAsync(StateHasChanged);
}
#endregion