Updated translation service and finished splitting out responsibilities for now
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using FictionArchive.Service.Shared.Models.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using NodaTime;
|
||||
|
||||
namespace FictionArchive.Service.Shared.Services.Database;
|
||||
|
||||
public class AuditInterceptor : SaveChangesInterceptor
|
||||
{
|
||||
public override InterceptionResult<int> SavingChanges(
|
||||
DbContextEventData eventData,
|
||||
InterceptionResult<int> result)
|
||||
{
|
||||
var context = eventData.Context;
|
||||
|
||||
if (context == null)
|
||||
return base.SavingChanges(eventData, result);
|
||||
|
||||
var entries = context.ChangeTracker.Entries<IAuditable>();
|
||||
|
||||
var now = Instant.FromDateTimeUtc(DateTime.UtcNow);
|
||||
|
||||
foreach (var e in entries)
|
||||
{
|
||||
if (e.State == EntityState.Added)
|
||||
{
|
||||
e.Entity.CreatedTime = now;
|
||||
e.Entity.LastUpdatedTime = now;
|
||||
}
|
||||
else if (e.State == EntityState.Modified)
|
||||
{
|
||||
e.Entity.LastUpdatedTime = now;
|
||||
}
|
||||
}
|
||||
|
||||
return base.SavingChanges(eventData, result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user