private static void OnEntityStateChangedHandler(object sender, EntityStateChangedEventArgs args)
 {
     if (args.Entry.Entity is BaseEntity entity && args.NewState == EntityState.Modified)
     {
         entity.UpdatedOn = DateTime.UtcNow;
     }
 }
Пример #2
0
 void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     if (e.NewState == EntityState.Modified && e.Entry.Entity is IEntityDate entity)
     {
         entity.EditTime = DateTimeOffset.Now;
     }
 }
Пример #3
0
 void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     if (e.NewState == EntityState.Modified && e.Entry.Entity is IHasLastModified entity)
     {
         entity.Updated_at = DateTime.UtcNow;
     }
 }
Пример #4
0
        private void Statechanged(object sender, EntityStateChangedEventArgs e)
        {
            int keyValue = GetKeyValue(e.Entry.Entity);

            Console.WriteLine($@"State of {e.Entry.Entity.GetType()} with Key = {keyValue} changed from " +
                              $"{e.OldState} to {e.NewState}");
        }
Пример #5
0
 void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     if (e.NewState == EntityState.Modified && e.Entry.Entity is IEntity entity)
     {
         entity.DateLastModifiedUtc = DateTime.UtcNow;
     }
 }
Пример #6
0
 private void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     if (e.NewState == EntityState.Modified && e.Entry.Entity is BaseEntity entity)
     {
         entity.ModifiedOn = DateTime.UtcNow;
     }
 }
 private static void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     if (e.NewState == EntityState.Modified && e.Entry.Entity is DbEntity entity)
     {
         entity.LastModifiedAt = DateTime.UtcNow;
     }
 }
Пример #8
0
        private void ChangeTracker_StateChanged(object sender, EntityStateChangedEventArgs e)
        {
            if (e.Entry.Entity is Car c)
            {
                var action = string.Empty;
                Console.WriteLine($"Blog {c.PetName} was {e.OldState} before the state changed to {e.NewState}");
                switch (e.NewState)
                {
                case EntityState.Added:
                case EntityState.Deleted:
                case EntityState.Modified:
                case EntityState.Unchanged:
                    switch (e.OldState)
                    {
                    case EntityState.Added:
                        action = "Added";
                        break;

                    case EntityState.Deleted:
                        action = "Deleted";
                        break;

                    case EntityState.Modified:
                        action = "Edited";
                        break;
                    }
                    Console.WriteLine($"The object was {action}");
                    break;
                }
            }
        }
Пример #9
0
 public static void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     if (e.Entry.Entity is Article article)
     {
         ParseMarkdown(article);
     }
 }
Пример #10
0
        private void StateChanged(object sender, EntityStateChangedEventArgs args)
        {
            _connection.InvokeAsync(
                nameof(DaBeeHub.ChangeState),
                new DaBeeEntityEntry(args.Entry, _trackingGuids[args.Entry.Entity]),
                args.OldState,
                false);

            IntroduceDelay();
        }
Пример #11
0
    protected virtual void OnEntityUpdate(object sender, EntityStateChangedEventArgs e)
    {
        var entity     = e.Entry.Entity;
        var entityType = entity.GetType();

        var implementsIEntity =
            entityType.GetInterfaces().Any(i => i.GetGenericTypeDefinition() == typeof(IEntity <>));

        if (e.NewState == EntityState.Modified && implementsIEntity)
        {
            var modifiedProperty = entityType.GetProperty(nameof(IEntity <object> .EditAt));
            modifiedProperty.SetValue(entity, DateTime.Now);
        }
    }
Пример #12
0
        private void ChangeTracker_StateChanged(object?sender, EntityStateChangedEventArgs e)
        {
            if (!(e.Entry.Entity is Car c))
            {
                return;
            }

            var action = string.Empty;

            Console.WriteLine($"Car {c.PetName} was {e.OldState} before the state changed to {e.NewState}");
            switch (e.NewState)
            {
            case EntityState.Added:
            case EntityState.Deleted:
            case EntityState.Modified:
            case EntityState.Unchanged:
                switch (e.OldState)
                {
                case EntityState.Added:
                    action = "Added";
                    break;

                case EntityState.Deleted:
                    action = "Deleted";
                    break;

                case EntityState.Modified:
                    action = "Edited";
                    break;

                case EntityState.Detached:
                case EntityState.Unchanged:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Console.WriteLine($"The object was {action}");
                break;

            case EntityState.Detached:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /// <summary>Tracks the auditable entity asynchronous.</summary>
        /// <param name="argument">The <see cref="EntityStateChangedEventArgs"/> instance containing the event data.</param>
        /// <returns></returns>
        protected async Task <bool> TrackAuditableEntityAsync(EntityStateChangedEventArgs argument)
        {
            bool b = false;

            switch (argument.NewState)
            {
            case EntityState.Detached:
            case EntityState.Unchanged:
                break;

            case EntityState.Deleted:
            case EntityState.Modified:
            case EntityState.Added:
                b = await TrackStatePrivateAsync(argument.Entry, argument.Entry.State);

                break;
            }
            return(b);
        }
Пример #14
0
        private void ChangeTracker_StateChanged(object?sender, EntityStateChangedEventArgs e)
        {
            if (e.Entry.Entity is not Car c)
            {
                return;
            }

            var action = string.Empty;

            Console.WriteLine($"Car {c.PetName} was {e.OldState} before the state changed to {e.NewState}");
            switch (e.NewState)
            {
            case EntityState.Unchanged:
                action = e.OldState switch
                {
                    EntityState.Added => "Added",
                    EntityState.Modified => "Edited",
                    _ => action
                };

                Console.WriteLine($"The object was {action}");
                break;
            }
        }
Пример #15
0
        private void ChangeTracker_StateChanged(object sender, EntityStateChangedEventArgs e)
        {
            // YOU CAN USE AN INTERFACE OR A BASE CLASS
            // But, for this demo, we are directly typecasting to Student model
            var student = e.Entry.Entity as Student;

            switch (e.Entry.State)
            {
            case EntityState.Deleted:
                student.DeletedOn = DateTime.Now;
                Console.WriteLine($"Marked for delete: {e.Entry.Entity}");
                break;

            case EntityState.Modified:
                student.ModifiedOn = DateTime.Now;
                Console.WriteLine($"Marked for update: {e.Entry.Entity}");
                break;

            case EntityState.Added:
                student.CreatedOn = DateTime.Now;
                Console.WriteLine($"Marked for insert: {e.Entry.Entity}");
                break;
            }
        }
Пример #16
0
 protected virtual void ChangeTracker_StateChanged(object sender, EntityStateChangedEventArgs e)
 {
     PublishEventsForTrackedEntity(e.Entry);
 }
Пример #17
0
 private static void ChangeTrackerOnStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     UpdateTimestampableObjects(e.Entry);
 }
Пример #18
0
 void OnEntityChanged(object sender, EntityStateChangedEventArgs e)
 {
     if (e.NewState == EntityState.Modified && e.Entry.Entity is DomainEntity entity)
     {
     }
 }
 void OnStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     //         if (e.NewState == EntityState.Modified && e.Entry.Entity is "EntidadeComAtributoLGPD" entity)
     //entity.LastModified = DateTime.Now;
 }
Пример #20
0
 void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
     ProcessLastModified(e.Entry);
 }
 private void OnEntityStateChanged(object sender, EntityStateChangedEventArgs e)
 {
 }