This question is locked. New answers and comments are not allowed.
First off, I been programming in .NET for a few years, but I just started w/ Silverlight this past week, so please keep your answers straight forward and don't assume anything. Thanks...
I have the following web service...
MyApp.svc.cs
namespace MyApp.Web { #region Data Types [DataContract] public class Record : INotifyPropertyChanged { private Guid _RecordID; private string _RecordName; private Boolean _Active; [DataMember] public Guid RecordID { get { return _RecordID; } set { _RecordID = value; OnPropertyChanged("RecordID"); } } [DataMember] public string RecordName { get { return _RecordName; } set { _RecordName = value; OnPropertyChanged("RecordName"); } } [DataMember] public Boolean Active { get { return _Active; } set { _Active = value; OnPropertyChanged("Active"); } } public event PropertyChangedEventHandler PropertyChanged; public void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } #endregion #region Classes [ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public class MyApp { [OperationContract] public List<Record> GetRecords() { return SampleRecords.Instance().GetRecords(); } [OperationContract] public Guid AddRecord(Record record) { return SampleRecords.Instance().AddRecord(record); } } #endregion } SampleRecords class:
namespace MyApp.Web { public class SampleRecords { public static SampleRecords Instance() { return (SampleRecords)Activator.CreateInstance(typeof(SampleRecords)); } public List<Record> GetRecords() { List<Record> records = new List<Record>(); Record record; try { using (SqlDataReader reader = SqlHelper.ExecuteReader(Globals.ConnectionString, "GetRecords")) { while (reader.Read()) { record = new Record(); record.RecordID = (Guid)reader["RecordID"]; record.RecordName = reader["Record"].ToString(); record.Active = Convert.ToBoolean(reader["Active"]); records.Add(record); } } } catch { } return records; } public Guid AddRecord(Record record) { return (Guid)SqlHelper.ExecuteScalar(Globals.ConnectionString, "AddRecord", record.RecordName, record.Active); } } }MainPage.xaml.cs (there's a RadGridView on the control - "rgvRecords"):
namespace SampleRecords { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); MyAppClient proxy = new MyAppClient(); proxy.GetRecordsCompleted += new EventHandler<GetRecordsCompletedEventArgs>(proxy_GetRecordsCompleted); proxy.GetRecordsAsync(); } void proxy_GetRecordsCompleted(object sender, GetRecordsCompletedEventArgs e) { try { rgvRecords.ItemsSource = e.Result; } catch { } } } }As you can see, I've pretty much got the guts of this done, but I guess my question is, Where do I call proxy.AddRecordAsync (and eventually proxy.DeleteRecordAsync)? Also, how does this all work with INotifyPropertyChanged?
Correct me if I'm wrong, but I'm assuming I use the AddingNewDataItem and call proxy.AddRecordAsync(record)? But then my question is, the AddRecord SQL stored procedure returns SCOPE_IDENTITY(). Does the returned identifier automatically get assigned to the new record in the RadGridView, or do I have to update it manually?
Like I said, I'm sure these are pretty basic questions, but I'm really having a hard time getting my head around the MVVM at the moment.
Thanks so much.
Joshua