コード例 #1
0
        private void SaveLogs(List <EfEntityInfo> entries)
        {
            foreach (var entity in entries)
            {
                LogEntryBase log = null;
                if (entity.State == EntityState.Modified)
                {
                    var beforeJson = Serialize(entity.OriginalValues);
                    var afterJson  = Serialize(entity.CurrentValues);
                    var diffJson   = JsonHelper.GetJsonDiff(beforeJson, afterJson);
                    log = CreateLogEntry(beforeJson, afterJson, diffJson, entity);
                }
                else if (entity.State == EntityState.Added)
                {
                    var beforeJson = "{}";
                    var afterJson  = Serialize(entity.CurrentValues);
                    var diffJson   = JsonHelper.GetJsonDiff(beforeJson, afterJson);
                    log = CreateLogEntry(beforeJson, afterJson, diffJson, entity);
                }
                else if (entity.State == EntityState.Deleted)
                {
                    var beforeJson = Serialize(entity.OriginalValues);
                    var afterJson  = "{deleted: true}";

                    log = CreateLogEntry(beforeJson, afterJson, "{deleted: true}", entity);
                }

                if (log != null)
                {
                    AddLogsToDatabase(log);
                }
            }
        }
コード例 #2
0
 protected virtual void AddLogsToDatabase(LogEntryBase log)
 {
 }