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:
@@ -61,29 +61,56 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method Load
|
||||
#region Public Method GetCount
|
||||
|
||||
/// <summary>
|
||||
/// Loads the count (a. beging, 23.05.2022)
|
||||
/// Gets the total count (ab)
|
||||
/// </summary>
|
||||
/// <param name="count">The count</param>
|
||||
/// <param name="type">The type</param>
|
||||
/// <returns>A task containing an operation result of list audit</returns>
|
||||
public async Task<OperationResult<List<Audit>>> Load(int count, AuditType? type = null)
|
||||
/// <returns>A task containing an operation result of count</returns>
|
||||
public async Task<OperationResult<int>> 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
|
||||
|
||||
/// <summary>
|
||||
/// Loads the page of audits (ab)
|
||||
/// </summary>
|
||||
/// <param name="skip">The skip count</param>
|
||||
/// <param name="take">The take count</param>
|
||||
/// <param name="type">The type</param>
|
||||
/// <returns>A task containing an operation result of list audit</returns>
|
||||
public async Task<OperationResult<List<Audit>>> 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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user