/// <summary> /// Initializes a new instance of the <see cref="BankAccount"/> class with specified parameters /// </summary> /// <param name="accountNumber">Account number</param> /// <param name="firstName">First name of the owner</param> /// <param name="lastName">Last name of the owner</param> /// <param name="invoiceAmount">Account balance</param> /// <param name="bonusScores">Bonus scores</param> /// <param name="accountType">Account type</param> /// <param name="isClosed">Account status</param> public BankAccount( string accountNumber, string firstName, string lastName, decimal invoiceAmount, double bonusScores, BancAccountType accountType, bool isClosed = false) { AccountNumber = accountNumber; FirstName = firstName; LastName = lastName; InvoiceAmount = invoiceAmount; BonuseScores = bonusScores; AccountType = accountType; IsClosed = isClosed; }
/// <summary> /// Reads accounts from file into list of accounts /// </summary> /// <returns>List of accounts</returns> /// <exception cref="IOException">Thrown when files reading error occurred</exception> private List <BankAccount> ReadAccounts() { List <BankAccount> accounts = new List <BankAccount>(); try { using (BinaryReader reader = new BinaryReader(File.Open(filePath, FileMode.Open))) { while (reader.PeekChar() > -1) { string number = reader.ReadString(); string firstName = reader.ReadString(); string lastName = reader.ReadString(); decimal invoiceAmount = reader.ReadDecimal(); double bonusScores = reader.ReadDouble(); BancAccountType type = (BancAccountType)reader.ReadInt32(); bool isClosed = reader.ReadBoolean(); BankAccount book = new BankAccount( number, firstName, lastName, invoiceAmount, bonusScores, type, isClosed); accounts.Add(book); } return(accounts); } } catch { throw new IOException("Unable to read from the file"); } }