Create Audits on Actions

This commit is contained in:
Andre Beging
2022-05-23 11:07:52 +02:00
parent 5d713db83f
commit b16951a1a6
11 changed files with 358 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
using FoodsharingSiegen.Contracts;
using FoodsharingSiegen.Contracts.Entity;
using FoodsharingSiegen.Server.Auth;
using Microsoft.EntityFrameworkCore;
namespace FoodsharingSiegen.Server.Data.Service
{
@@ -36,6 +37,7 @@ namespace FoodsharingSiegen.Server.Data.Service
{
var audit = new Audit
{
Created = DateTime.Now,
Type = type,
UserID = CurrentUser?.Id,
Data1 = data1,
@@ -66,11 +68,11 @@ namespace FoodsharingSiegen.Server.Data.Service
/// <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)
public async Task<OperationResult<List<Audit>>> Load(int count, AuditType? type = null)
{
try
{
var query = Context.Audits?.OrderBy(x => x.Created).AsQueryable();
var query = Context.Audits?.Include(x => x.User).OrderByDescending(x => x.Created).AsQueryable();
if (count > 0)
query = query?.Take(count);