/// <summary>
 /// Save <see cref="AuditClassPropertyChange"/>
 /// </summary>
 /// <param name="session"><see cref="ISession"/></param>
 /// <param name="audit"><see cref="Audit"/></param>
 /// <param name="auditClassProperty"><see cref="AuditClassProperty"/></param>
 /// <param name="oldValue">Old value</param>
 /// <param name="newValue">New value</param>
 internal static void Save(ISession session, Audit audit, AuditClassProperty auditClassProperty, string oldValue, string newValue)
 {
     session.Save(new AuditClassPropertyChange
     {
         Audit    = audit,
         Property = auditClassProperty,
         NewValue = newValue,
         OldValue = oldValue
     });
 }
예제 #2
0
        /// <summary>
        /// Save <see cref="Audit"/>
        /// </summary>
        /// <param name="event"><see cref="PreUpdateEvent"/></param>
        internal static void Save(PreUpdateEvent @event)
        {
            var differences = AuditDifference.Retrieve(@event);

            if (!differences.Any())
            {
                return;
            }

            var session    = @event.Session.GetSession(EntityMode.Poco);
            var auditClass = AuditClass.Find(session, @event.Entity.GetType().FullName);
            var auditable  = (IAuditable)@event.Entity;

            if (auditClass == null)
            {
                return;
            }

            if (string.IsNullOrWhiteSpace(auditable.AuditDescription))
            {
                auditable.AuditDescription = "{0} updated".With(auditClass.Description);
            }

            var audit = Save(session,
                             @event.Id.ToString(),
                             auditable.AuditGroupReference,
                             auditClass,
                             AuditType.Update(),
                             auditable.AuditDescription,
                             auditable.AuditUser);

            foreach (var difference in differences)
            {
                AuditClassPropertyChange.Save(session,
                                              audit,
                                              AuditClassProperty.Find(session, auditClass, difference.Property),
                                              difference.OldValue,
                                              difference.NewValue);
            }
        }