Creado apartir del commit b888de6c92056de294456f581a56e25e734d4ab7 de develop
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
using System.Security.Claims;
|
||||
using adas_core.Application.Services.Interfaces;
|
||||
using audit_logs.Services.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace adas_core.Application.Services;
|
||||
|
||||
public class LocalAuditService(
|
||||
IAuditService auditService,
|
||||
ILogger<LocalAuditService> logger)
|
||||
: ILocalAuditService
|
||||
{
|
||||
public async Task CreateAuditLogAsync(ClaimsPrincipal? user, object? dataOriginal, object? dataModified,
|
||||
string? reason)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (reason != null)
|
||||
{
|
||||
await auditService.CreateAuditLogAsync(user, dataOriginal!, dataModified!, reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ = user?.FindFirst(ClaimTypes.Name)?.Value ?? "Not specified";
|
||||
|
||||
await auditService.CreateAuditLogAsync(user, dataOriginal!, dataModified!);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<T?> DeepCopyAsync<T>(T data)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await auditService.DeepCopyAsync(data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning("Error copying object, trying with JsonDeepCopyAsync. Exception: {Message}", ex.Message);
|
||||
try
|
||||
{
|
||||
var copy = await auditService.JsonDeepCopyAsync(data);
|
||||
return copy;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.LogError(e, "Error in fallback copy method. Exception: {Message}", e.Message);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user