I've got a Xaml page that I'm using ListView on to display a list of offers. I'm trying to Get offers using a REST Web API call to display on the page using an ObservableCollection. Since async calls don't seem to work on ObservableCollection methods, I've moved that to a public async task method under the public ObservableCollection GetOffers() method. Here is my code.
public class OffersService : IOffersService
{
public ObservableCollection<OffersModel> GetOffers()
{
var offersList = new ObservableCollection<OffersModel> ();
var offers = GetOffersAsyncOC ();
OffersModel model = new OffersModel () {
Id = Guid.NewGuid (),
OfferImage = null,
OfferType = "Dollar Off",
Name = "Test name",
Description = "Test Description",
Amount = 25,
StartDate = DateTime.Now.Date,
EndDate = DateTime.Now.Date.AddHours (8),
};
offersList.Add (model);
return offersList;
}
As you can see, I'm using the GetOffersAsyncOC method to get a list of offers. I'm then manually adding an offer for testing purposes because I can't seem to find a way to add the offers from the Rest API to the ObservableCollection. For testing purposes, this works, but I need to be able to work with data coming from the Rest API.
Any help is much appreciated. I've been developing for less than a year, so I may need a little more explanation than usual. Thanks!