public AuditEntry(EntityEntry entry, IAuditUserProvider auditUserProvider) { Entry = entry; ReadablePrimaryKey = Entry.ToReadablePrimaryKey(); HashReferenceId = ReadablePrimaryKey.ToGuidHash(); TableName = entry.Metadata.GetTableName(); DisplayName = entry.Metadata.DisplayName(); SchemaName = entry.Metadata.GetSchema(); EntityState = entry.State; ByUser = auditUserProvider == default ? "Unknown" : auditUserProvider.GetUser(); foreach (PropertyEntry property in entry.Properties) { if (property.IsAuditable()) { if (property.IsTemporary) { TemporaryProperties.Add(property); continue; } string propertyName = property.Metadata.Name; switch (entry.State) { case EntityState.Added: NewValues[propertyName] = property.CurrentValue; break; case EntityState.Deleted: OldValues[propertyName] = property.OriginalValue; break; case EntityState.Modified: if (property.IsModified) { OldValues[propertyName] = property.OriginalValue; NewValues[propertyName] = property.CurrentValue; } break; } } } }
public PersonDbContext(DbContextOptions <PersonDbContext> options, IAuditUserProvider auditUserProvider) : base(options, auditUserProvider) { }
public AuditDbContextBase(DbContextOptions <TDbContext> options, IAuditUserProvider auditUserProvider) : base(options) { this.auditUserProvider = auditUserProvider; }