public static async Task DeleteBoodSchappenLijstje(BoodschappenLijstje b) { IList <BoodschappenLijstje> Boodschappenlijstjes = await GetBoodschappenLijstjes(); foreach (BoodschappenLijstje bt in Boodschappenlijstjes) { if (bt.supermarkt.Name == b.supermarkt.Name) { Boodschappenlijstjes.Remove(bt); break; } } try { StorageFile file = await localFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting); if (file != null) { string JsonString = JsonConvert.SerializeObject(await GetBoodschappenLijstjes()); await FileIO.WriteTextAsync(file, JsonString); } } catch (Exception) { //Could not save? OHOH } }
public static async Task DeleteProductFromBoodschappenLijstje(Supermarkt supermarkt, Product product) { IList <BoodschappenLijstje> Boodschappenlijstjes = await GetBoodschappenLijstjes(); BoodschappenLijstje BoodschappenLijstje = null; foreach (BoodschappenLijstje b in Boodschappenlijstjes) { if (b.supermarkt.Name == supermarkt.Name) { BoodschappenLijstje = b; break; } } foreach (BoodschappenlijstjeItem bi in BoodschappenLijstje.Producten) { if (bi.SupermarktItem.Name == product.Name) { BoodschappenLijstje.Producten.Remove(bi); break; } } if (BoodschappenLijstje.Producten.Count == 0) { Boodschappenlijstjes.Remove(BoodschappenLijstje); } BoodschappenLijstje.Notify(); try { StorageFile file = await localFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting); if (file != null) { string JsonString = JsonConvert.SerializeObject(await GetBoodschappenLijstjes()); await FileIO.WriteTextAsync(file, JsonString); } } catch (Exception) { //Could not save? OHOH } }
public static async Task AddProductToBoodschappenLijstje(Supermarkt supermarkt, int Count) { if (supermarkt.ProductPagina.SelectedItem == null) { return; } IList <BoodschappenLijstje> Boodschappenlijstjes = await GetBoodschappenLijstjes(); BoodschappenLijstje BoodschappenLijstje = null; foreach (BoodschappenLijstje b in Boodschappenlijstjes) { if (b.supermarkt.Name == supermarkt.Name) { BoodschappenLijstje = b; break; } } if (BoodschappenLijstje == null) { BoodschappenLijstje = new BoodschappenLijstje(supermarkt); Boodschappenlijstjes.Add(BoodschappenLijstje); } foreach (BoodschappenlijstjeItem bi in BoodschappenLijstje.Producten) { if (bi.SupermarktItem.Name == supermarkt.ProductPagina.SelectedItem.Name) { BoodschappenLijstje.Producten.Remove(bi); break; } } if (Count > 0) { BoodschappenLijstje.Producten.Add(new BoodschappenlijstjeItem(Count, supermarkt.ProductPagina.SelectedItem)); } else { if (BoodschappenLijstje.Producten.Count == 0) { Boodschappenlijstjes.Remove(BoodschappenLijstje); } } try { StorageFile file = await localFolder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting); if (file != null) { string JsonString = JsonConvert.SerializeObject(await GetBoodschappenLijstjes()); await FileIO.WriteTextAsync(file, JsonString); } } catch (Exception) { //Could not save? OHOH } return; }