public static async Task UpdateGalleryAsync(this SQLiteDatabase database, IPictureGallery gallery) { if (!gallery.Id.HasValue) { // If the gallery doesn't have an ID, assume that it's new, and attempt to add it. await database.AddGalleryAsync(gallery); } else { // Update the gallery in the database. IPictureGallery oldGallery = await database.GetGalleryAsync(gallery.Id); IEnumerable <IPicture> deletedPictures = oldGallery.Where(oldPicture => !gallery.Any(picture => oldPicture.Id == picture.Id)); IEnumerable <IPicture> newPictures = gallery.Where(picture => !oldGallery.Any(oldPicture => picture.Id == oldPicture.Id)); foreach (IPicture picture in deletedPictures) { await database.RemovePictureAsync(gallery, picture); } foreach (IPicture picture in newPictures) { await database.AddPictureAsync(gallery, picture); } } }
public static async Task AddGalleryAsync(this SQLiteDatabase database, IPictureGallery gallery) { await database.AddGalleryAsync(gallery.Name); IPictureGallery newGallery = await database.GetGalleryAsync(gallery.Name); await database.UpdateGalleryAsync(new PictureGallery(newGallery.Id, gallery.Name, gallery.Pictures)); }