예제 #1
0
        public override void OnPreInsert(DbContext context, DbEntityEntry entry)
        {
            if (!this.ShouldAudit(entry))
                return;

            this.currentInsert = this.CreateAudit(context, entry, EntityAuditAction.Insert);
            entry
                .CurrentValues
                .PropertyNames
                .Select(entry.Property)
                .ToList()
                .ForEach(x =>
                    this.currentInsert.Properties.Add(new EntityAuditProperty {
                        PropertyName = x.Name,
                        OldValue = String.Empty,
                        NewValue = this.ObjectToString(context, x.CurrentValue)
                    })
                );

            base.OnPreInsert(context, entry);
        }
예제 #2
0
 protected virtual void OnAuditStoreUpdate(EntityAudit audit, DbContext context, DbEntityEntry entry)
 {
     auditContext.Audits.Add(audit);
 }
예제 #3
0
 protected virtual EntityAudit CreateAudit(DbContext context, DbEntityEntry entry, EntityAuditAction action)
 {
     var audit = new EntityAudit {
         Action = action,
         EntityId = this.GetEntityId(context, entry),
         EntityType = entry.Entity.GetType().FullName,
         DateCreatedUtc = DateTime.UtcNow,
         Properties = new List<EntityAuditProperty>()
     };
     return audit;
 }