diff --git a/FoodsharingSiegen.Server/Data/Service/AuditService.cs b/FoodsharingSiegen.Server/Data/Service/AuditService.cs
index dd3b715..2f13c51 100644
--- a/FoodsharingSiegen.Server/Data/Service/AuditService.cs
+++ b/FoodsharingSiegen.Server/Data/Service/AuditService.cs
@@ -61,29 +61,56 @@ namespace FoodsharingSiegen.Server.Data.Service
#endregion
- #region Public Method Load
+ #region Public Method GetCount
///
- /// Loads the count (a. beging, 23.05.2022)
+ /// Gets the total count (ab)
///
- /// The count
/// The type
- /// A task containing an operation result of list audit
- public async Task>> Load(int count, AuditType? type = null)
+ /// A task containing an operation result of count
+ public async Task> GetCount(AuditType? type = null)
{
try
{
- await Task.CompletedTask;
-
- var query = Context.Audits?.Include(x => x.User).OrderByDescending(x => x.Created).AsQueryable();
+ var query = Context.Audits?.AsQueryable();
- if (count > 0)
- query = query?.Take(count);
-
if (type != null)
query = query?.Where(x => x.Type == type);
- var mat = query?.ToList();
+ if (query == null) return new(0);
+
+ var count = await query.CountAsync();
+ return new(count);
+ }
+ catch (Exception e)
+ {
+ return new(e);
+ }
+ }
+
+ #endregion
+
+ #region Public Method LoadPage
+
+ ///
+ /// Loads the page of audits (ab)
+ ///
+ /// The skip count
+ /// The take count
+ /// The type
+ /// A task containing an operation result of list audit
+ public async Task>> LoadPage(int skip, int take, AuditType? type = null)
+ {
+ try
+ {
+ var query = Context.Audits?.Include(x => x.User).OrderByDescending(x => x.Created).AsQueryable();
+
+ if (type != null)
+ query = query?.Where(x => x.Type == type);
+
+ query = query?.Skip(skip).Take(take);
+
+ var mat = await query!.ToListAsync();
if (mat != null) return new(mat);
diff --git a/FoodsharingSiegen.Server/Pages/AuditView.razor b/FoodsharingSiegen.Server/Pages/AuditView.razor
index 8222a48..438fd14 100644
--- a/FoodsharingSiegen.Server/Pages/AuditView.razor
+++ b/FoodsharingSiegen.Server/Pages/AuditView.razor
@@ -13,6 +13,8 @@
diff --git a/FoodsharingSiegen.Server/Pages/AuditView.razor.cs b/FoodsharingSiegen.Server/Pages/AuditView.razor.cs
index bc60999..89e4076 100644
--- a/FoodsharingSiegen.Server/Pages/AuditView.razor.cs
+++ b/FoodsharingSiegen.Server/Pages/AuditView.razor.cs
@@ -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
///
private List? Audits { get; set; }
+ ///
+ /// Gets or sets the value of the total audits (ab)
+ ///
+ private int TotalAudits { get; set; }
+
#endregion
#region Override InitializeDataAsync
///
- 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
+
+ ///
+ /// Called when data is read (ab)
+ ///
+ /// The params
+ private async Task OnReadData(DataGridReadDataEventArgs 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