示例#1
0
        private static async Task CreateLogEntry(
            LoggingDbContext context,
            string userId,
            bool asyncOperation,
            DateTime logTime,
            JsonDiffPatch jdp,
            EntityState state,
#if NETSTANDARD
            EntityEntry item
示例#2
0
        private static async Task LogChangesAddedEntitiesAsync(this LoggingDbContext context, string userId, bool asyncOperation)
        {
            var logTime = context.UseUtcTime ? DateTime.UtcNow : DateTime.Now;
            var jdp     = new JsonDiffPatch();

            foreach (var item in context.AddedEntities)
            {
                await CreateLogEntry(context, userId, asyncOperation, logTime, jdp, EntityState.Added, item);
            }
        }
示例#3
0
        private static async Task LogChangesAsync(this LoggingDbContext context, string userId, bool asyncOperation)
        {
            var logTime = context.UseUtcTime ? DateTime.UtcNow : DateTime.Now;
            var changes = context.ChangeTracker.Entries()
                          .Where(x => entityStates.Contains(x.State) &&
                                 GetEntityType(x.Entity.GetType()) != null)
                          .ToList();
            var jdp = new JsonDiffPatch();

            foreach (var item in changes)
            {
                if (context.IdGeneratedByDatabase &&
                    item.State == EntityState.Added)
                {
                    context.AddedEntities.Add(item);
                    continue;
                }

                await CreateLogEntry(context, userId, asyncOperation, logTime, jdp, item.State, item);
            }
        }
示例#4
0
 internal static async Task LogChangesAddedEntitiesAsync(this LoggingDbContext context, string userId)
 => await LogChangesAddedEntitiesAsync(context, userId, true);
示例#5
0
 internal static void LogChangesAddedEntities(this LoggingDbContext context, string userId)
 => LogChangesAddedEntitiesAsync(context, userId, false).GetAwaiter().GetResult();