mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
implement audit log view in webfront
This commit is contained in:
@ -71,8 +71,8 @@ namespace SharedLibraryCore.Database
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
// optionsBuilder.UseLoggerFactory(_loggerFactory)
|
||||
// .EnableSensitiveDataLogging();
|
||||
optionsBuilder.UseLoggerFactory(_loggerFactory)
|
||||
.EnableSensitiveDataLogging();
|
||||
|
||||
if (string.IsNullOrEmpty(_ConnectionString))
|
||||
{
|
||||
|
57
SharedLibraryCore/Dtos/AuditInfo.cs
Normal file
57
SharedLibraryCore/Dtos/AuditInfo.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
|
||||
namespace SharedLibraryCore.Dtos
|
||||
{
|
||||
/// <summary>
|
||||
/// data transfer class for audit information
|
||||
/// </summary>
|
||||
public class AuditInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// name of the origin entity
|
||||
/// </summary>
|
||||
public string OriginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// id of the origin entity
|
||||
/// </summary>
|
||||
public int OriginId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// name of the target entity
|
||||
/// </summary>
|
||||
public string TargetName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// id of the target entity
|
||||
/// </summary>
|
||||
public int? TargetId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// when the audit event occured
|
||||
/// </summary>
|
||||
public DateTime When { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// what audit action occured
|
||||
/// </summary>
|
||||
public string Action { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// additional comment data about the audit event
|
||||
/// </summary>
|
||||
public string Data { get; set; }
|
||||
|
||||
private string oldValue;
|
||||
/// <summary>
|
||||
/// previous value
|
||||
/// </summary>
|
||||
public string OldValue { get => oldValue ?? "--"; set => oldValue = value; }
|
||||
|
||||
private string newValue;
|
||||
/// <summary>
|
||||
/// new value
|
||||
/// </summary>
|
||||
public string NewValue { get => newValue ?? "--"; set => newValue = value; }
|
||||
}
|
||||
}
|
34
SharedLibraryCore/Dtos/PaginationInfo.cs
Normal file
34
SharedLibraryCore/Dtos/PaginationInfo.cs
Normal file
@ -0,0 +1,34 @@
|
||||
namespace SharedLibraryCore.Dtos
|
||||
{
|
||||
/// <summary>
|
||||
/// pagination information holder class
|
||||
/// </summary>
|
||||
public class PaginationInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// how many items to skip
|
||||
/// </summary>
|
||||
public int Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// how many itesm to take
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// filter query
|
||||
/// </summary>
|
||||
public string Filter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// direction of ordering
|
||||
/// </summary>
|
||||
public SortDirection Direction { get; set; } = SortDirection.Descending;
|
||||
}
|
||||
|
||||
public enum SortDirection
|
||||
{
|
||||
Ascending,
|
||||
Descending
|
||||
}
|
||||
}
|
19
SharedLibraryCore/Interfaces/IAuditInformationRepository.cs
Normal file
19
SharedLibraryCore/Interfaces/IAuditInformationRepository.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using SharedLibraryCore.Dtos;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// describes the capabilities of the audit info repository
|
||||
/// </summary>
|
||||
public interface IAuditInformationRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// retrieves a list of audit information for given pagination params
|
||||
/// </summary>
|
||||
/// <param name="paginationInfo">pagination info</param>
|
||||
/// <returns></returns>
|
||||
Task<IList<AuditInfo>> ListAuditInformation(PaginationInfo paginationInfo);
|
||||
}
|
||||
}
|
55
SharedLibraryCore/Repositories/AuditInformationRepository.cs
Normal file
55
SharedLibraryCore/Repositories/AuditInformationRepository.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SharedLibraryCore.Dtos;
|
||||
using SharedLibraryCore.Interfaces;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// implementation if IAuditInformationRepository
|
||||
/// </summary>
|
||||
public class AuditInformationRepository : IAuditInformationRepository
|
||||
{
|
||||
private readonly IDatabaseContextFactory _contextFactory;
|
||||
|
||||
public AuditInformationRepository(IDatabaseContextFactory contextFactory)
|
||||
{
|
||||
_contextFactory = contextFactory;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<IList<AuditInfo>> ListAuditInformation(PaginationInfo paginationInfo)
|
||||
{
|
||||
using (var ctx = _contextFactory.CreateContext(enableTracking: false))
|
||||
{
|
||||
var iqItems = (from change in ctx.EFChangeHistory
|
||||
where change.TypeOfChange != Database.Models.EFChangeHistory.ChangeType.Ban
|
||||
orderby change.TimeChanged descending
|
||||
join originClient in ctx.Clients
|
||||
on (change.ImpersonationEntityId ?? change.OriginEntityId) equals originClient.ClientId
|
||||
join targetClient in ctx.Clients
|
||||
on change.TargetEntityId equals targetClient.ClientId
|
||||
into targetChange
|
||||
from targetClient in targetChange.DefaultIfEmpty()
|
||||
select new AuditInfo()
|
||||
{
|
||||
Action = change.TypeOfChange.ToString(),
|
||||
OriginName = originClient.CurrentAlias.Name,
|
||||
OriginId = originClient.ClientId,
|
||||
TargetName = targetClient == null ? "" : targetClient.CurrentAlias.Name,
|
||||
TargetId = targetClient == null ? new int?() : targetClient.ClientId,
|
||||
When = change.TimeChanged,
|
||||
Data = change.Comment,
|
||||
OldValue = change.PreviousValue,
|
||||
NewValue = change.CurrentValue
|
||||
})
|
||||
.Skip(paginationInfo.Offset)
|
||||
.Take(paginationInfo.Count);
|
||||
|
||||
return await iqItems.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user