I use Breeze.js and C# WebAPI with BreezeController. I want to update an entity on the client web page, pass it to the WebAPI for update, save the entity, and send back a warning(s).
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle) {}
Is there a way to return SaveResult with information about a warning? Not an error, a warning.
Example, I'm saving the age of a resident. If the age is < than 50 [that is not an error] I still want to warn the user that this may be an incorrect age for a resident based on my business rules.
saveResult.Errors.Add(new EntityError() {
PropertyName = "Age",
ErrorName = "Warning",
ErrorMessage = "The age of the resident is less than 50. You may want to verify that you entered the correct age."
});
If I do this (This is the behavior I want):
- The entity is correctly saved.
- The Warning message is sent back in the saveResult structure.
- The entity is correctly updated on the server and sent back with the saveResult (i.e. system generated primary key of my entity contains a new ID).
However (This is NOT the behavior I want):
- On the client, the Entity is not updated. i.e the PK is not updated and the Entity is still in a pending state (not saved).
I'm sure that the fact that I return an error in the SaveResult is the problem since Breeze.js is probably interpreting this (correctly) as an error. However, I don't see how to return the warning using the Breeze model and still have everything functional.
By the way, I know I could be doing that validation on the client side before calling the WebAPI but I want all my validations to be server side, especially since some of these validations are quite complex.
Any suggestions?