public static void SaveWallet(bool firstSave = false) { var dbUserData = new DBUserData(); // If data has never been inserted, do this now if (firstSave) { dbUserData.SaveResources(); return; } // Before we save, we want to check if there has been any tradeoffers the user placed which have been bought. // If there are, we want to add the income of that tradeoffer to the wallet before saving it, so that income won't get overwritten. var offers = dbUserData.CheckForCompletedTrades(); var dbTrading = new DBTrading(); foreach (var offer in offers) { // Add the resources that were requested to the wallet. var currency = (Currencies)Enum.Parse(typeof(Currencies), offer.RequestedCurrency); Wallet[currency] = Convert.ToInt32(Wallet[currency]) + Convert.ToInt32(offer.RequestedAmount); dbTrading.UpdateProcessed(offer); } dbUserData.UpdateResources(Wallet); }
public Hashtable LoadWallet() { var db = new DBUserData(); Wallet = db.LoadResources(); // It Wallet is null, this is the first time the user plays the game and we need to insert a new resources record for him if (Wallet == null) { SaveWallet(true); Wallet = db.LoadResources(); } return(Wallet); }