0

i want to know how to insert MobileServiceCollection from Windows Azure to my ObservableCollection from JSON web service

private ObservableCollection<AddressDetail> _hereRestAddressDetail = null;
public ObservableCollection<AddressDetail> hereRestAddressDetail
{
    get { return _hereRestAddressDetail; }
    set { this.SetProperty(ref this._hereRestAddressDetail, value); }
}



private async void UpdateTransportDetail()
{
    try
    {
       WebClient client = new WebClient();
       client.DownloadStringCompleted += (s, e) =>
       {
           if (e.Error == null)
            {
               RootObjectDetail result = JsonConvert.DeserializeObject<RootObjectDetail>(e.Result);
               hereRestAddressDetail.Clear();
               hereRestAddressDetail.Insert(0,result);    
            }
            else
            {
               isFailed = Visibility.Visible;
               isFailedMessage = "Can't get data from web server, please refresh and make sure your internet data connected";
            }
        };
        client.DownloadStringAsync(new Uri(hrefText + transportDetailURL));
        hereRestAddressDetail = await addressTable.ToCollectionAsync();
     }
     catch (Exception)
     {
         isFailed = Visibility.Visible;
         isFailedMessage = "Something wrong happen, please refresh";
     }
}

and what i try to do is to add my azure data into the next entry of hereRestAddressDetail (since the first is from json web service) with this

hereRestAddressDetail = await addressTable.ToCollectionAsync();

but it just replace the data from json not adding it, how can i make it appear with my json data also?

puretppc
  • 3,232
  • 8
  • 38
  • 65

1 Answers1

0

Not sure if the question is still actual, but you can replace the while collection

hereRestAddressDetail = new ObservableCollection<AddressDetail>(await addressTable.ToCollectionAsync());

Or (i'd recommend this way) grab OptimizedObservableCollection ( for example, here: http://www.pedrolamas.com/2013/05/08/cimbalino-windows-phone-toolkit-updated-to-v2-3-0/ ) and use it like

hereRestAddressDetail.ReplaceWith(await addressTable.ToCollectionAsync()); // replace
or 
hereRestAddressDetail.AddRange(await addressTable.ToCollectionAsync()); // add
Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64