View Full Version : Send different actions to the backend

Renan Cunha
23 Jun 2013, 4:29 PM
I have a doubt about which approach to use in this situation:

In our system here we have an grid of orders. The data is handled by a store that uses an ajax or rest (this varies) proxy. For the basic operations (crud) everything is fine, the problem is that the orders have another "operations" that isn't an update. For example, I have a button to proces the order, basically it will update the status of the order. I cannot simply update the status and then sync the store, because we have a complex system of permissions. An user can update the data of a order but him cannot process.

How I will differentiate these actions on the server side? My idea was to have two actions in my controller at backend (C# WebAPI)...


23 Jun 2013, 10:48 PM
one idea could be to add an extra field to your store's model and use the value of this field to distinguish the two cases of update on the backend...

24 Jun 2013, 5:14 PM
I typically have non-crud actions that are context-specific in the context menu. So when you right-click on a grid record, a list of available options will appear.

For actions where I don't want to interact with the data record directly, I will often fire off ad-hoc AJAX requests (not using the store's proxy), and then use the response from the request to update any values needed within the store. For example, when changing statuses, I make a non-store based AJAX request, which in turn returns the new status of the record, which is then updated within the store. I do the data update manually in the response.

Not necessarily the best fit for every scenario, but I found it was easier to manage than updating the full store record every time.

Re: differentiating the actions, this is handled easily in my scenario, as the endpoint url of the ad-hoc AJAX request can be anything I want. So for status updates, I can point to status-specific endpoints, etc.

Renan Cunha
24 Jun 2013, 6:03 PM
Thanks for the answers!
I implemented two ways for then analyze what is more "nice" to use.

The first way is exactly how @existdissolve says. Making an ad-hoc AJAX call specific to this cases.

The second that I implemented was add an "extraParam" before calling the store sync method and then the back-end route this param to his place. Like the answer of @Farish.

The two ways has worked well for me!

How I can mark this topic as answered?