public void AuditChanges(object userName, ExpandoObject metadata)
        {
            // Get all Deleted/Modified entities (not Unmodified or Detached or Added)
            foreach (
                DbEntityEntry ent in
                _context.ChangeTracker.Entries()
                .Where(p => p.State == EntityState.Deleted || p.State == EntityState.Modified))
            {
                using (var auditer = new LogAuditor(ent))
                {
                    var eventType = GetEventType(ent);

                    AuditLog record = auditer.CreateLogRecord(userName, eventType, _context, metadata);

                    if (record != null)
                    {
                        var arg = new AuditLogGeneratedEventArgs(record, ent.Entity, metadata);
                        RaiseOnAuditLogGenerated(this, arg);
                        if (!arg.SkipSavingLog)
                        {
                            _context.AuditLog.Add(record);
                        }
                    }
                }
            }
        }
Example #2
0
 public static void AuditAdditions(ITrackerContext dbContext, object userName,
                                   IEnumerable <DbEntityEntry> addedEntries)
 {
     // Get all Added entities
     foreach (DbEntityEntry ent in addedEntries)
     {
         using (var auditer = new LogAuditor(ent))
         {
             AuditLog record = auditer.CreateLogRecord(userName, EventType.Added, dbContext);
             if (record != null)
             {
                 dbContext.AuditLog.Add(record);
             }
         }
     }
 }
Example #3
0
 public static void AuditChanges(ITrackerContext dbContext, object userName)
 {
     // Get all Deleted/Modified entities (not Unmodified or Detached or Added)
     foreach (
         DbEntityEntry ent in
         dbContext.ChangeTracker.Entries()
         .Where(p => p.State == EntityState.Deleted || p.State == EntityState.Modified))
     {
         using (var auditer = new LogAuditor(ent))
         {
             AuditLog record = auditer.CreateLogRecord(userName,
                                                       ent.State == EntityState.Modified ? EventType.Modified : EventType.Deleted, dbContext);
             if (record != null)
             {
                 dbContext.AuditLog.Add(record);
             }
         }
     }
 }
 public void AuditAdditions(object userName, IEnumerable <DbEntityEntry> addedEntries, ExpandoObject metadata)
 {
     // Get all Added entities
     foreach (DbEntityEntry ent in addedEntries)
     {
         using (var auditer = new LogAuditor(ent))
         {
             AuditLog record = auditer.CreateLogRecord(userName, EventType.Added, _context, metadata);
             if (record != null)
             {
                 var arg = new AuditLogGeneratedEventArgs(record, ent.Entity, metadata);
                 RaiseOnAuditLogGenerated(this, arg);
                 if (!arg.SkipSavingLog)
                 {
                     _context.AuditLog.Add(record);
                 }
             }
         }
     }
 }