Esempio n. 1
0
        /// <summary>
        /// Save <see cref="Audit"/>
        /// </summary>
        /// <param name="event"><see cref="PreDeleteEvent"/></param>
        internal static void Save(PreDeleteEvent @event)
        {
            if ([email protected]().GetInterfaces().Contains(typeof(IAuditable)))
            {
                return;
            }

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

            if (auditClass == null)
            {
                return;
            }

            var auditable = (IAuditable)@event.Entity;

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

            Save(session, @event.Id.ToString(), auditable.AuditGroupReference, auditClass, AuditType.Delete(),
                 auditable.AuditDescription, auditable.AuditUser);
        }
Esempio n. 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);
            }
        }