Ejemplo n.º 1
0
        private void Events_EntityMerged(object sender, EntityMergedEventArgs e)
        {
            if (e.Modified)
            {
                string   userName = _sessionInfoProvider.GetCurrentUser();
                DateTime dateTime = _sessionInfoProvider.GetCurrentDateTime();

                string annotationKey = typeof(AuditingPluginMetadata).FullName;
                var    annotation    = e.EntityEntry.Metadata.FindAnnotation(annotationKey);
                if (annotation != null)
                {
                    AuditingPluginMetadata props = (AuditingPluginMetadata)annotation.Value;

                    if (props.ModifiedBy != null)
                    {
                        e.EntityEntry.Property(props.ModifiedBy.Name).CurrentValue = userName;
                    }

                    if (props.ModifiedDate != null)
                    {
                        e.EntityEntry.Property(props.ModifiedDate.Name).CurrentValue = props.GetValueForDate(props.ModifiedDate.ClrType, dateTime);
                    }
                }
            }
        }
        public static AuditingPluginMetadata GetMetadata(EntityType entityType)
        {
            AuditingPluginMetadata auditInfo;
            string annotationKey = typeof(AuditingPluginMetadata).FullName;
            var    annotation    = entityType.FindAnnotation(annotationKey);

            if (annotation == null)
            {
                auditInfo = new AuditingPluginMetadata();
                entityType.SetAnnotation(annotationKey, auditInfo, ConfigurationSource.Explicit);
            }
            else
            {
                auditInfo = (AuditingPluginMetadata)annotation.Value;
            }
            return(auditInfo);
        }