Exemple #1
0
 public void WriteNewShoppingInstance(Shopping purchaseInstance)
 {
     purchaseInstance.FinalizePurchase();
     ((JArray)shoppingDatabaseJson[nameof(Shopping.purchasedItems)]).Add(JObject.FromObject(purchaseInstance));
     purchaseDatabase.Add(purchaseInstance.date, purchaseInstance);
     File.WriteAllText(WPFHelper.dataPath + current.ToString() + "db.json", shoppingDatabaseJson.ToString());
 }
Exemple #2
0
 private void LoadPurchaseDatabase()
 {
     purchaseDatabase = new Dictionary <DateTime, Shopping>();
     using (StreamReader sr = File.OpenText(selectedShopDBFile.FullName)) {
         using (JsonTextReader jr = new JsonTextReader(sr)) {
             shoppingDatabaseJson = JToken.ReadFrom(jr);
             JArray array = ((JArray)shoppingDatabaseJson["purchases"]);
             for (int i = 0; i < array.Count; i++)
             {
                 Shopping item = array[i].ToObject <Shopping>();
                 purchaseDatabase.Add(item.date, item);
             }
         }
     }
 }