public void OnAfterSaveChanges(List <DataAuditEntry> auditEntries) { if (auditEntries == null || auditEntries.Count == 0) { return; } for (int i = 0; i < auditEntries.Count; i++) { var auditEntry = auditEntries[i]; for (int j = 0; j < auditEntry.TemporaryProperties.Count; j++) { var prop = auditEntry.TemporaryProperties[j]; if (prop.Metadata.IsPrimaryKey()) { auditEntry.KeyValues[prop.Metadata.Name] = prop.CurrentValue; } else { auditEntry.NewValues[prop.Metadata.Name] = prop.CurrentValue; } } _context.DataAudit.Add(auditEntry.ToAudit()); } _context.SaveChanges(); }
public int Complete(int loggedUserId) { var helper = new AuditHelper(_context, loggedUserId); var remaining = helper.OnBeforeSaveChanges(); int result = _context.SaveChanges(); helper.OnAfterSaveChanges(remaining); return(result); }