From 47150387f10c521d2bb35cdc716671dc613e6f29 Mon Sep 17 00:00:00 2001 From: Chris Ingham Date: Wed, 25 Oct 2023 11:50:53 -0600 Subject: [PATCH 1/2] 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; } } } From 7bdc79c389a9ab22f4bafb28015307f5e610159c Mon Sep 17 00:00:00 2001 From: inghamc Date: Fri, 19 Jan 2024 14:33:52 -0700 Subject: [PATCH 2/2] Rebase to 8.0.0 release; Nicer pattern matching syntax --- .../Data/Interceptors/AuditableEntityInterceptor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs b/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs index 9cbb3ec3c..3d584516c 100644 --- a/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs +++ b/src/Infrastructure/Data/Interceptors/AuditableEntityInterceptor.cs @@ -39,7 +39,7 @@ public void UpdateEntities(DbContext? context) foreach (var entry in context.ChangeTracker.Entries()) { - if (entry.State == EntityState.Added || entry.State == EntityState.Modified || entry.HasChangedOwnedEntities()) + if (entry.State is EntityState.Added or EntityState.Modified || entry.HasChangedOwnedEntities()) { var utcNow = _dateTime.GetUtcNow(); if (entry.State == EntityState.Added)