Following on from Part 1, we’ll now add insert, update and delete methods to our WCFRIA domain service.
Update your PersonService.cs class as follows:
Note I’m using attributes here to explicitly define the operations for Insert, Update and Delete. I could have left these off as WCFRIA Services picks up Insert/Create/Add within the method for Insert, Update/Edit and Updates and Remove/Delete for deletions but I prefer to keep things explicit.
We are also overriding the Submit method here, which isn’t required but get’s called by the client proxy and passes back the changed item set before each of the the insert/update/delete methods are called for the individual changed items.
We'll keep the GUI real simple with just a datagrid, save button and status textblock but you'll see how powerful the grid is shortly: MainPage.xaml
Finally update your code behind on the server, note the callback methods for each of the service calls. Remember all service calls are async in Silverlight and I reckon including the call back methods to response to any errors that might have occurred during the service call: MainPage.xaml.cs
On start up our service loads the data grid with data:
As our generated strongly typed Person object knows an Age is both required and an integer, the data grid automatically picks up the validation notifications and displays them to the user.
When we update the data with valid info and click save our success message shows us our service call encountered no errors.
The source code for this project can be downloaded here:
http://stevenhollidge.com/blog-source-code/WcfRiaWithPocos-part2.zip
No comments:
Post a Comment