From f4b5d95b4bcfdf0c42a0731169ce593606ace725 Mon Sep 17 00:00:00 2001 From: Chris Ingham Date: Wed, 25 Oct 2023 11:50:53 -0600 Subject: [PATCH] Use the Created DateTimeOffset for initial LastModified in MainAuditableEntityInterceptor.UpdateEntities --- .../Interceptors/AuditableEntityInterceptor.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs b/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs index 1d4ae77d3..9cbb3ec3c 100644 --- a/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs +++ b/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs @@ -39,16 +39,16 @@ public void UpdateEntities(DbContext? context) foreach (var entry in context.ChangeTracker.Entries()) { - if (entry.State == EntityState.Added) - { - entry.Entity.CreatedBy = _user.Id; - entry.Entity.Created = _dateTime.GetUtcNow(); - } - if (entry.State == EntityState.Added || entry.State == EntityState.Modified || entry.HasChangedOwnedEntities()) { + var utcNow = _dateTime.GetUtcNow(); + if (entry.State == EntityState.Added) + { + entry.Entity.CreatedBy = _user.Id; + entry.Entity.Created = utcNow; + } entry.Entity.LastModifiedBy = _user.Id; - entry.Entity.LastModified = _dateTime.GetUtcNow(); + entry.Entity.LastModified = utcNow; } } }