When saving a certain entity I want to send a notification email if the Approved
property of this entity has changed.
if (changedEntity.Entity is Option)
{
// Pseudo
if changedEntity.Entity.Approved changed {
send notification()
}
}
Is there a certain way to do this? Or can it be done by comparing the CurrentValues
against the OriginalValues
?
If you know the specific entity that you want to 'watch', you can use the EntityAspect.propertyChanged event (see: http://breeze.github.io/doc-js/api-docs/classes/EntityAspect.html#event_propertyChanged) like this:
// assume order is an order entity attached to an EntityManager.
myEntity.entityAspect.propertyChanged.subscribe(function(propertyChangedArgs) {
// this code will be executed anytime a property value changes on the 'myEntity' entity.
if ( propertyChangedArgs.propertyName === "Approved") {
// perform your logic here.
}
});
Or if you want to watch a specific property on every entity, you can perform a similar test using the EntityManger.entityChanged event (see: http://breeze.github.io/doc-js/api-docs/classes/EntityManager.html#event_entityChanged)
myEntityManager.entityChanged.subscribe(function (args) {
// entity will be the entity that was just changed;
var entity = args.entity;
// entityAction will be the type of change that occured.
var entityAction = args.entityAction;
if (entityAction == breeze.EntityAction.PropertyChange) {
var propChangArgs = args.args;
if (propChangeArgs.propertyName === "Approved") {
// perform your logic here
}
}
});
More detail can be found here: http://breeze.github.io/doc-js/lap-changetracking.html