//transfer public void PerformTransfer(IAccounts from, IAccounts to, decimal amount, string description, DateTimeOffset transferDate) { if (from.AccountNumber.Substring(0, 2) == to.AccountNumber.Substring(0, 2)) { // substract money from sender from.bal -= amount; // add money to reciever to.bal += amount; //creating trasaction logs: there is one transaction for each accout, so in total two logs needed // log for sender statementrow statement1 = new statementrow(); statement1.account = from; statement1.tran_amount = amount; statement1.tran_date = transferDate; statement1.description = description; statement1.aftertran_balance = from.Balance; this.TransactionLog.Add(statement1); // log for reciever statementrow statement2 = new statementrow(); statement2.account = to; statement2.tran_amount = amount; statement2.tran_date = transferDate; statement2.description = description; statement2.aftertran_balance = to.Balance; this.TransactionLog.Add(statement2); //print outout Console.WriteLine(); Console.WriteLine(">Transfering " + amount + " from " + from.AccountNumber + " to " + to.AccountNumber); Console.WriteLine(">Transaction date " + transferDate); Console.WriteLine(">Message: " + description); Console.WriteLine(); Console.WriteLine("*******************************"); }// prevent users transfer money to a diff type of account (SV to LN) else { Console.WriteLine(); Console.WriteLine(">Transaction failed: You can't tranfer to a different type of account!"); Console.WriteLine(); Console.WriteLine("*******************************"); } }
//last five transacation logs for the given account public IEnumerable <statementrow> GetMiniStatement(IAccounts account) { List <statementrow> took = new List <statementrow> { }; foreach (var x in this.TransactionLog) { if (x.account == account) { took.Add(x); } } //**Here the transactions were made in time order and the GetMiniStatment operates in the same order //**so what we need is just reverse the for loop for (int i = took.Count; i > took.Count - 5; i--) { statementrow a = took[i - 1]; yield return(a); } }
//withdrawal public void PerformWithdrawal(IAccounts account, decimal amount, string description, DateTimeOffset withdrawalDate) { // substact money from account account.bal -= amount; //creating a new transcaction log statementrow statement = new statementrow(); statement.account = account; statement.tran_amount = amount; statement.tran_date = withdrawalDate; statement.description = description; statement.aftertran_balance = account.Balance; this.TransactionLog.Add(statement); //print output Console.WriteLine(); Console.WriteLine(">Withdrawaling " + amount + " from " + account.AccountNumber); Console.WriteLine(">Transaction date " + withdrawalDate); Console.WriteLine(">Message: " + description); Console.WriteLine(">Balance after transaction: " + this.GetBalance(account)); Console.WriteLine(); Console.WriteLine("*******************************"); }
//deposit public void PerformDeposit(IAccounts account, decimal amount, string description, DateTimeOffset depositDate) { //adding money into account account.bal += amount; //creating a new transaction log statementrow statement = new statementrow(); statement.account = account; statement.tran_amount = amount; statement.tran_date = depositDate; statement.description = description; statement.aftertran_balance = account.Balance; this.TransactionLog.Add(statement); //print outout Console.WriteLine(); Console.WriteLine(">Depositing " + amount + " into " + account.AccountNumber); Console.WriteLine(">Transaction date " + depositDate); Console.WriteLine(">Message: " + description); Console.WriteLine(">Balance after transaction: " + this.GetBalance(account)); Console.WriteLine(); Console.WriteLine("*******************************"); }