public async Task <bool> UpdateArticlesAsync(List <NewsItem> items) { try { var allArticles = await _dbConnection.Table <NewsItem>().ToListAsync(); if (allArticles != null) { foreach (var item in items) { if (allArticles.Find(o => o.id == item.id) == null) { await _dbConnection.InsertAsync(item); } else { await _dbConnection.UpdateAsync(item); } } } else { await _dbConnection.InsertAllAsync(items); } } catch (Exception e) { return(false); } return(true); }
/// <summary> /// Inserts items, as lists /// </summary> /// <returns>The or update async.</returns> /// <param name="items">Items.</param> public async System.Threading.Tasks.Task <int> InsertOrUpdateAsync(System.Collections.Generic.List <CommunicationIcon> items) { database.DropTableAsync <CommunicationIcon>().Wait(); database.CreateTableAsync <CommunicationIcon>().Wait(); return(await database?.InsertAllAsync(items)); }
/** * Gets a list of clubs using a filter * if the filter is null, then all clubs are returned * */ public static async Task <List <Club> > getListClubsAsync(Func <Club, bool> filtre) { if (filtre == null) { filtre = x => true; } SQLite.SQLiteAsyncConnection connection = DependencyService.Get <ISQLiteDb>().GetConnectionAsync(); List <Club> clubs = new List <Club>(); await connection.CreateTableAsync <Club>(); clubs = (await SQLiteNetExtensionsAsync.Extensions.ReadOperations.GetAllWithChildrenAsync <Club>(connection)); if (clubs.Count == 0)//if no clubs in the datatbase { //parse the default clubs from the XML files and add them (Ressources/Clubs) clubs = GolfXMLReader.getListClubFromXMLFiles(); await connection.InsertAllAsync(clubs); } return(clubs); }