public async Task <bool> Commit() { foreach (var entry in ChangeTracker.Entries().Where(entry => entry.Entity.GetType().GetProperty("CreatedDate") != null)) { if (entry.State == EntityState.Added) { entry.Property("CreatedDate").CurrentValue = DateTime.Now; } if (entry.State == EntityState.Modified) { entry.Property("CreatedDate").IsModified = false; } } foreach (var entry in ChangeTracker.Entries().Where(entry => entry.Entity.GetType().GetProperty("UpdatedDate") != null)) { if (entry.State == EntityState.Modified) { entry.Property("UpdatedDate").CurrentValue = DateTime.Now; } } var success = await base.SaveChangesAsync() > 0; if (success) { await _mediatorHandler.PublishEvents(this); } return(success); }
public async Task <bool> Commit() { var success = await SaveChangesAsync() > 0; if (success) { await _mediator.PublishEvents(this); } return(success); }
public async Task <bool> Commit() { //ChangeTracker -> EF: change mapper foreach (var entry in ChangeTracker.Entries().Where(entry => entry.Entity.GetType().GetProperty("CreatedDate") != null)) { if (entry.State == EntityState.Added) { entry.Property("CreatedDate").CurrentValue = DateTime.Now; } if (entry.State == EntityState.Modified) { entry.Property("CreatedDate").IsModified = false; //Ignore to update any value set for the property = "CreatedDate" } } var success = await base.SaveChangesAsync() > 0; if (success) { await _mediatorHandler.PublishEvents(this); //Call the mediator extension to publish the events } return(success); }