Ejemplo n.º 1
0
 public void After(InterceptionContext context)
 {
     foreach (var entryWithState in context.EntriesByState)
     {
         foreach (var entry in entryWithState)
         {
             After(entry, entryWithState.Key);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Executes after the changes to the context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void After(InterceptionContext context)
        {
            using (var repository = _repositoryFactory())
            {
                foreach (var entryWithState in context.EntriesByState.Where(x => x.Key != EntityState.Unchanged)) // added unchanged filter, so we don't log events for objects that haven't been changed
                {
                    foreach (var entry in entryWithState.Where(x => x.Entity is Entity))
                    {
                        var now = DateTime.UtcNow;
                        var entityType = entry.Entity.GetType();
                        if (entityType.BaseType != null && entityType.Namespace == "System.Data.Entity.DynamicProxies")
                        {
                            entityType = entityType.BaseType;
                        }

                        if (_entityTypes == null || IsMatchInExpression(_entityTypes, entityType.Name))
                        {
                            var activityLog = StateEntry2OperationLog(entityType.Name, now, ((Entity)entry.Entity).Id, entryWithState.Key);
                            if (_policy == ChangeLogPolicy.Cumulative)
                            {
                                var alreadyExistLog = repository.OperationLogs.OrderByDescending(x => x.ModifiedDate)
                                                                .FirstOrDefault(x => x.ObjectId == activityLog.ObjectId && x.ObjectType == activityLog.ObjectType);
                                if (alreadyExistLog != null)
                                {
                                    alreadyExistLog.ModifiedBy = activityLog.ModifiedBy;
                                    alreadyExistLog.ModifiedDate = activityLog.ModifiedDate;
                                    alreadyExistLog.OperationType = activityLog.OperationType;

                                }
                                else
                                {
                                    repository.Add(activityLog);
                                }
                            }
                            else
                            {
                                repository.Add(activityLog);
                            }
                        }
                    }
                }

                repository.UnitOfWork.Commit();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Befores the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Before(InterceptionContext context)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Befores the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Before(InterceptionContext context)
 {
 }
Ejemplo n.º 5
0
 public void Before(InterceptionContext context)
 {
     foreach (var entry in context.Entries)
         Before(entry);
 }