Reputation: 71
I'm thinking at the following scenario: on the client-side you update two entities and you submit the POST with the json bundle. On the server side you do an interception and apply some business logic. The save works for one of the entities, however for the other one it fails. In your opinion what will be the correct solution and why: 1. should I do a rollback and return an exception on the client, or 2. commit the update for the 1st entity and return a message that the save worked only for one of the entities? I know that the guys from IdeaBlade consider the saveChanges as a single transaction(so all CRUD functionality goes in a single POST), so judging by this I think 1. should be correct approach. However I appreciate all reasoned opinions.Thanks!
Upvotes: 0
Views: 243
Reputation: 171
Well it depends on what your doing. I bet you would save a lot of time developing if you just roll back. If you really want to though, you can return a list of failed and successful entities saved. Then the user (assuming the errors are user errors) can make the changes on the errored entities and commit only them again. This may become difficult though. Breeze attaches a state to each entity, which you will need now need to manage. So on the response, you'll need to figure out which entities failed and which succeeded, then update their state on the client, otherwise you'll resubmit commits that you don't need to. I think it would be a better investment on time to put this business logic on the client, then roll back on the server (and log the event so you can fix it) for the rare occasions errors occur. Does that help?
Upvotes: 1