private Dictionary <string, Account> RetrieveAccounts() { Dictionary <string, Account> accounts = new Dictionary <string, Account>(); StreamReader sr = null; try { sr = new StreamReader("Accounts.txt"); string row = ""; while ((row = sr.ReadLine()) != null) { Account a = AccountMapper.ToAccount(row); accounts.Add(a.AccountNumber, a); } } catch (FileNotFoundException fileNotFound) { Console.WriteLine(fileNotFound.FileName + " was not found"); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (sr != null) { sr.Close(); } } return(accounts); }
public void SaveAccount(Account account) { Dictionary <string, Account> accounts = new Dictionary <string, Account>(); accounts = RetrieveAccounts(); accounts[account.AccountNumber] = account; StreamWriter sw = new StreamWriter("Accounts.txt"); foreach (Account item in accounts.Values) { sw.WriteLine(AccountMapper.ToString(item)); sw.Flush(); } if (sw != null) { sw.Close(); } }