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