public ActionResult LoadRepo([FromServices] CurrencyRepo repo)
        {
            IFormatter   formatter = new BinaryFormatter();
            string       docPath   = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            Stream       stream    = new FileStream(Path.Combine(docPath, "Repo.txt"), FileMode.Open, FileAccess.Read);
            CurrencyRepo temp      = (CurrencyRepo)formatter.Deserialize(stream);

            stream.Close();
            //makes sure that the coins are added to the global repo so that the other window/view model can
            //see the coins add in this window
            repo.Coins = temp.Coins;
            //reduce the number of coins when the repo is loaded
            repo.ReduceCoins();
            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        //deserialize and load a repo from a file
        private void ExecuteCommandLoad(object parameter)
        {
            IFormatter   formatter = new BinaryFormatter();
            Stream       stream    = new FileStream(@"...\Repo.txt", FileMode.Open, FileAccess.Read);
            CurrencyRepo temp      = (CurrencyRepo)formatter.Deserialize(stream);

            stream.Close();
            //makes sure that the coins are added to the global repo so that the other window/view model can
            //see the coins add in this window
            foreach (ICoin c in temp.Coins)
            {
                repo.AddCoin(c);
            }
            //reduce the number of coins when the repo is loaded
            repo.ReduceCoins();
            RaisePropertyChanged("TotalAmount");
        }