Skip to content

Commit

Permalink
Use the Created DateTimeOffset for initial LastModified in MainAudita…
Browse files Browse the repository at this point in the history
…bleEntityInterceptor.UpdateEntities
  • Loading branch information
inghamc committed Oct 25, 2023
1 parent d11a7fb commit f4b5d95
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public void UpdateEntities(DbContext? context)

foreach (var entry in context.ChangeTracker.Entries<BaseAuditableEntity>())
{
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;
}
}
}
Expand Down

0 comments on commit f4b5d95

Please sign in to comment.