Exemple #1
0
        public override int SaveChanges()
        {
            IEnumerable <EntityEntry> modified = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified || e.State == EntityState.Added);

            foreach (EntityEntry item in modified)
            {
                IDateTracking changedOrAddedItem = item.Entity as IDateTracking;
                if (changedOrAddedItem != null)
                {
                    if (item.State == EntityState.Added)
                    {
                        changedOrAddedItem.DateCreated = DateTime.Now;
                    }
                    changedOrAddedItem.DateModified = DateTime.Now;
                }
            }
            return(base.SaveChanges());
        }
Exemple #2
0
        public override int SaveChanges()
        {
            var modified = ChangeTracker.Entries().Where(e => e.State == EntityState.Modified || e.State == EntityState.Added);

            foreach (EntityEntry item in modified)
            {
                IDateTracking changedOrAddedItem = item.Entity as IDateTracking;
                if (changedOrAddedItem != null)
                {
                    if (item.State == EntityState.Added)
                    {
                        changedOrAddedItem.DateCreated = ConvertDatetime.ConvertToTimeSpan(DateTime.Now);
                    }
                    changedOrAddedItem.DateModified = ConvertDatetime.ConvertToTimeSpan(DateTime.Now);
                }
            }
            return base.SaveChanges();
        }