public Task AddNewListItems(libNewsBlog.RootObject rootObject) { //_connection.Dispose(); //var a = rootObject.items.Count; _connection.DeleteAll <NewsListItem>(); foreach (var i in rootObject.items) { var Newitem = new NewsListItem(i); { if (!_connection.Table <NewsListItem>().Any(x => x.id == Newitem.id)) { _connection.Insert(Newitem); } else { _connection.Update(Newitem); } } } return(Task.Run(() => rootObject)); }
//HttpClient client; //public OnlineDataNews() //{ //} public async Task <IEnumerable <NewsListItem> > GetNewsAsync() { //var client = new HttpClient(); //var NewsString = await client.GetStringAsync(NewsApiUrls.Base); //NewsString = NewsString.Substring(NewsString.IndexOf("[", System.StringComparison.CurrentCulture)); //NewsString = NewsString.Substring(0, NewsString.LastIndexOf("]", System.StringComparison.CurrentCulture) + 1); //NewsTable = JsonConvert.DeserializeObject<List<NewsListItem>>(NewsString); if (!initialized) { Init(); } List <NewsListItem> newlists = new List <NewsListItem>(); try { // create a file, overwriting any existing fileMySubFolder IFolder folder = await rootFolder.CreateFolderAsync("Library", CreationCollisionOption.OpenIfExists); IFile Newsfile = await folder.CreateFileAsync("News.json", CreationCollisionOption.OpenIfExists); var json = await Newsfile.ReadAllTextAsync(); //populate the file with some text googleNews = JsonConvert.DeserializeObject <libNewsBlog.RootObject>(json); foreach (var item in googleNews.items) { NewsListItem newslist = new NewsListItem(item); newlists.Add(newslist); } } catch (Exception) { } //await SyncNewsAsync(); return(await Task.Run(() => newlists)); //sqlite.GetNewListItems()); }