コード例 #1
0
 public static AuditTrailChangeLogResource FromEntity(AuditTrailChangeLogEntity entity)
 {
     return(new AuditTrailChangeLogResource()
     {
         ColumnName = entity.ColumnName,
         ValueBefore = entity.ValueBefore,
         ValueAfter = entity.ValueAfter
     });
 }
コード例 #2
0
ファイル: AuditTrailRepository.cs プロジェクト: rikp777/Cyto
        private List <AuditTrailChangeLogEntity> GetChanges()
        {
            //_context.
            // var myObjectState= _context.ObjectStateManager.GetObjectStateEntry(myObject);
            //var modifiedProperties=myObjectState.GetModifiedProperties();

            var changes          = new List <AuditTrailChangeLogEntity>();
            var modifiedEntities = _context.ChangeTracker.Entries()
                                   .Where(p => p.State == EntityState.Modified)
                                   .ToList();

            if (modifiedEntities.Count <= 0)
            {
                return(changes);
            }

            foreach (var change in modifiedEntities)
            {
                foreach (var columnName in change.OriginalValues.PropertyNames)
                {
                    var originalValue = change.GetDatabaseValues().GetValue <object>(columnName).ToString();
                    var currentValue  = change.CurrentValues[columnName].ToString();
                    if (originalValue != currentValue)
                    {
                        var auditChangeLog = new AuditTrailChangeLogEntity
                        {
                            ColumnName  = columnName,
                            ValueBefore = originalValue,
                            ValueAfter  = currentValue
                        };
                        changes.Add(auditChangeLog);

                        Console.WriteLine(@"Audit Trail: 'Value Changed': [Original value: " + originalValue + @"] - [Current value: " + currentValue + @"] - [Column name: " + columnName + @"]");
                    }
                }
            }
            return(changes);
        }