This is a migrated thread and some comments may be shown as answers.

MVVM add new record

1 Answer 59 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul O'Flaherty
Top achievements
Rank 1
Paul O'Flaherty asked on 23 Sep 2010, 03:45 PM
Hi

I have an app(silverlight) that i'm messing around with and my scenario is as follows: 

1. I have a WCF service setup so that it will return a list of customers(This is not using EF, RIA services etc. - just a webservice that calls sps that return the records)

2. I have a Model of customers that i fill with this information. 

3. I then have a public property of ObservableCollection<Customers> in my ViewModel. 

4. In my View i have a grid which is bound to the customer property in the ViewModel.

When i run it and i load the customers from my service everything runs perfectly.

Customer:
CustomerID(AutogeneratedID - SQL server)
Name
Address

What is the procedure for adding new customers?  If i let the user enter the Name and Address fields and call the storedProcedure for inserting the new customer this should return the new AutogeneratedID for the new customer - i think i should be able to get this to work.

Do i then have to reload the data into the customer Model?, then reload the data into the ObservableCollection<Customer> in the ViewModel so that i can see/read the new CustomerID?

Have you any examples of this?  I know it's not specific to your controls but this is what i need to be able to do.

Again i'm not using RIA services, EF, I'm just calling a stored procedure reading results and filling a Model.  I can't find any examples on the web for this.

Thanks
Paul 

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 29 Sep 2010, 08:57 AM
Hi Paul O'Flaherty,

Basically, there is no need to reload the whole data once you add a new item. What you can do is to handle the RowEditEnded event of the grid. In case the EditOperationType is "Insert", you can call your custom Stored Procedure and get back the value for CustomerID. Afterwards, all you need to do is to update the property related to that CustomerID.
 

Greetings,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Paul O'Flaherty
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or