private static async Task CreateLogEntry( LoggingDbContext context, string userId, bool asyncOperation, DateTime logTime, JsonDiffPatch jdp, EntityState state, #if NETSTANDARD EntityEntry item
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); } }
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); } }
internal static async Task LogChangesAddedEntitiesAsync(this LoggingDbContext context, string userId) => await LogChangesAddedEntitiesAsync(context, userId, true);
internal static void LogChangesAddedEntities(this LoggingDbContext context, string userId) => LogChangesAddedEntitiesAsync(context, userId, false).GetAwaiter().GetResult();