コード例 #1
0
        public void RemoveAccount(AccountDal account)
        {
            var accounts = new List <AccountDal>(GetBankAccounts());

            accounts.Remove(FindAccount(account, accounts));
            SetBankAccounts(accounts);
        }
コード例 #2
0
 public void AddAccount(AccountDal account)
 {
     using (FileStream fs = File.Open(_filePath, FileMode.Append))
         using (BinaryWriter writer = new BinaryWriter(fs))
         {
             WriteAccount(account, writer);
         }
 }
コード例 #3
0
 private void WriteAccount(AccountDal account, BinaryWriter writer)
 {
     writer.Write(account.Number);
     writer.Write((int)account.Type);
     writer.Write(account.FirstName);
     writer.Write(account.LastName);
     writer.Write(account.Balance);
     writer.Write(account.Bonus);
 }
コード例 #4
0
        private AccountDal FindAccount(AccountDal account, IEnumerable <AccountDal> accounts)
        {
            AccountDal resultAccount = null;

            foreach (var acc in accounts)
            {
                if (acc.Number == account.Number)
                {
                    resultAccount = acc;
                }
            }

            if (ReferenceEquals(resultAccount, null))
            {
                throw new AccountNotFoundException("An error occurred while searching for an account.");
            }

            return(resultAccount);
        }