public void After(InterceptionContext context)
 {
     foreach (var entryWithState in context.EntriesByState)
     {
         foreach (var entry in entryWithState)
         {
             After(entry, entryWithState.Key);
         }
     }
 }
        /// <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();
            }
        }
 /// <summary>
 /// Befores the specified context.
 /// </summary>
 /// <param name="context">The context.</param>
 public void Before(InterceptionContext context)
 {
 }
 public void Before(InterceptionContext context)
 {
     foreach (var entry in context.Entries)
         Before(entry);
 }