Exemple #1
0
        /// <summary>
        /// More info: http://www.dotnettips.info/post/2507
        /// </summary>
        public static void SetAuditableEntityPropertyValues(
            this ChangeTracker changeTracker,
            AppShadowProperties props)
        {
            if (props == null)
            {
                return;
            }

            var modifiedEntries = changeTracker.Entries <IAuditableEntity>()
                                  .Where(x => x.State == EntityState.Modified);

            foreach (var modifiedEntry in modifiedEntries)
            {
                modifiedEntry.SetModifiedShadowProperties(props);
            }

            var addedEntries = changeTracker.Entries <IAuditableEntity>()
                               .Where(x => x.State == EntityState.Added);

            foreach (var addedEntry in addedEntries)
            {
                addedEntry.SetAddedShadowProperties(props);
            }
        }
Exemple #2
0
        public static void SetModifiedShadowProperties(this EntityEntry <IAuditableEntity> modifiedEntry, AppShadowProperties props)
        {
            if (props == null)
            {
                return;
            }

            modifiedEntry.Property(ModifiedDateTime).CurrentValue = props.Now;
            if (!string.IsNullOrWhiteSpace(props.UserAgent))
            {
                modifiedEntry.Property(ModifiedByBrowserName).CurrentValue = props.UserAgent;
            }
            if (!string.IsNullOrWhiteSpace(props.UserIp))
            {
                modifiedEntry.Property(ModifiedByIp).CurrentValue = props.UserIp;
            }
            if (!string.IsNullOrEmpty(props.UserId))
            {
                modifiedEntry.Property(ModifiedByUserId).CurrentValue = props.UserId;
            }
        }
Exemple #3
0
        public static void SetAddedShadowProperties(this EntityEntry <AppLogItem> addedEntry, AppShadowProperties props)
        {
            if (props == null)
            {
                return;
            }

            addedEntry.Property(CreatedDateTime).CurrentValue = props.Now;
            if (!string.IsNullOrWhiteSpace(props.UserAgent))
            {
                addedEntry.Property(CreatedByBrowserName).CurrentValue = props.UserAgent;
            }
            if (!string.IsNullOrWhiteSpace(props.UserIp))
            {
                addedEntry.Property(CreatedByIp).CurrentValue = props.UserIp;
            }
            if (!string.IsNullOrEmpty(props.UserId))
            {
                addedEntry.Property(CreatedByUserId).CurrentValue = props.UserId;
            }
        }