using Blazorise.DataGrid; using FoodsharingSiegen.Contracts.Entity; using FoodsharingSiegen.Contracts.Helper; using FoodsharingSiegen.Server.Data.Service; using Microsoft.AspNetCore.Components; namespace FoodsharingSiegen.Server.Pages { /// /// The audit view class (a. beging, 23.05.2022) /// public partial class AuditView { #region Dependencies /// /// Gets or sets the value of the audit service (ab) /// [Inject] public AuditService? AuditService { get; set; } #endregion #region Private Properties /// /// Gets or sets the value of the audits (ab) /// 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 Task InitializeDataAsync() { if (!CurrentUser.IsAdmin()) NavigationManager.NavigateTo("/"); return Task.CompletedTask; } #endregion #region Private Method OnReadData /// /// Called when data is read (ab) /// /// The params private async Task OnReadData(DataGridReadDataEventArgs e) { if (!CurrentUser.IsAdmin()) return; 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 } }