Change object on client side or on server side

Posted by Polina Feterman on Stack Overflow See other posts from Stack Overflow or by Polina Feterman
Published on 2012-11-22T10:04:50Z Indexed on 2012/11/22 11:00 UTC
Read the original article Hit count: 128

I'm not sure what is the best practice.
I have some big and complex objects (NOT flat).
In that object I have many related objects - for example Invoice is the main class and one of it's properties is invoiceSupervisor - a big class by it's own called User.
User can also be not flat and have department property - also an object called Department.

For example I want create new Invoice.

First way:
I can present to client several fields to fill in. Some of them will be combos that I will need to fill with available values. For example available invoiceSupervisors. Then all the chosen values I can send to server and on server I can create new Invoice and assign all chosen values to that new Invoice. Then I will need to assign new supervisor I will pull the chosen User by id that user picked up on server from combobox. I might do some verification on the User such as does the user applicable to be invoice supervisor. Then I will assign the User object to invoiceSupervisor. Then after filling all properties I will save the new invoice.

Second way:
In the beginning I can call to server to get a new Invoice. Then on client I can fill all chosen values , for example I can call to server to get new User object and then fill it's id from combobox and assign the User as invoiceSupervisor. After filling the Invoice object on client I can send it to server and then the server will save the new invoice. Before saving server can run some validations as well.

So what is the best approach - to make the object on client and send it to server or to collect all values from client and to make a new object on server using those values ?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about ASP.NET