public ActionResult <BankAccount> CreateAccount([FromBody] BankAccount account) { if (!ModelState.IsValid) { return(BadRequest("Invalid Bank Account!")); } if (account.type == "Checking") { CheckingAccount newAcc = new CheckingAccount(); newAcc.lastName = account.lastName; newAcc.firstName = account.firstName; newAcc.type = account.type; newAcc.Balance = account.Balance; id++; newAcc.Id = id; if (account.Balance < 200) { newAcc.ApplyFee(); } using (var db = new BankContext()) { db.checkingAccounts.Add(newAcc); db.SaveChanges(); return(db.checkingAccounts.Last()); } } else { SavingsAccount newAcc = new SavingsAccount(); newAcc.lastName = account.lastName; newAcc.firstName = account.firstName; newAcc.type = account.type; newAcc.Balance = account.Balance; id++; newAcc.Id = id; if (account.Balance > 800) { newAcc.ApplyInterest(); } using (var db = new BankContext()) { db.savingsAccounts.Add(newAcc); db.SaveChanges(); return(db.savingsAccounts.Last()); } } }
static void Main(string[] args) { { CheckingAccount c1 = new CheckingAccount("Sam", 100); SavingsAccount s1 = new SavingsAccount("John", 500, 100); Console.WriteLine("Account Information #1"); Console.WriteLine(c1.ToString()); Console.WriteLine(s1.ToString()); Console.WriteLine("\n\nTransactions on c1:"); Console.WriteLine("Withdraw $200 from c1: " + c1.Withdraw(200)); Console.WriteLine(c1.ToString()); Console.WriteLine("Withdraw $60 from c1: " + c1.Withdraw(60)); Console.WriteLine(c1.ToString()); Console.WriteLine("Deposit $500 to c1: " + c1.Deposit(500)); Console.WriteLine(c1.ToString()); Console.WriteLine("Withdraw $200 from c1: " + c1.Withdraw(200)); Console.WriteLine(c1.ToString()); Console.WriteLine("\n\nTransactions on s1:"); Console.WriteLine("Withdraw $400: " + s1.Withdraw(400)); Console.WriteLine(s1.ToString()); Console.WriteLine("Withdraw $200: " + s1.Withdraw(200)); Console.WriteLine(s1.ToString()); Console.WriteLine("Deposit $600: " + s1.Deposit(600)); Console.WriteLine(s1.ToString()); Console.WriteLine("Withdraw $400: " + s1.Withdraw(400)); Console.WriteLine(s1.ToString()); Console.WriteLine("Apply Interest: " + s1.ApplyInterest()); Console.WriteLine(s1.ToString()); Console.Write("\n\nPress Enter to exit the program:"); Console.ReadLine(); } }
static void Main(string[] args) { Console.WriteLine("Welcome to Ace Bank!"); Console.WriteLine(); CheckingAccount michaelsAccount = new CheckingAccount("Michael", 5000); CheckingAccount gobsAccount = new CheckingAccount("Gob", 2000); Console.WriteLine("Open Accounts:"); Console.WriteLine(); PrintAccountDetails(michaelsAccount); Console.WriteLine(); PrintAccountDetails(gobsAccount); Console.WriteLine(); Console.WriteLine("Making transfer of $1000.00..."); try { Thread.Sleep(500); } catch (ThreadInterruptedException) { return; } michaelsAccount.Transfer(gobsAccount, 1000); Console.WriteLine("Updated Account Details:"); Console.WriteLine(); PrintAccountDetails(michaelsAccount); Console.WriteLine(); PrintAccountDetails(gobsAccount); Console.WriteLine(); // Initialize new savings account with initial balance of $30,000 and 0.89% interest SavingsAccount acesSavingsAccount = new SavingsAccount("Ace", 30000, .0089); SavingsAccount garysSavingsAccount = new SavingsAccount("Gary", 10000, .0056); SavingsAccount kaelsSavingsAccount = new SavingsAccount("Kael", 1500, 0.043); Console.WriteLine("Open Accounts:"); Console.WriteLine(); PrintSavingsAccountDetails(acesSavingsAccount); Console.WriteLine(); PrintSavingsAccountDetails(garysSavingsAccount); Console.WriteLine(); PrintSavingsAccountDetails(kaelsSavingsAccount); Console.WriteLine(); acesSavingsAccount.Transfer(garysSavingsAccount, 5000); Console.WriteLine("Making transfer of $5000.00..."); try { Thread.Sleep(500); } catch (ThreadInterruptedException) { return; } Console.WriteLine("Updated Savings Account Details:"); Console.WriteLine(); PrintSavingsAccountDetails(acesSavingsAccount); Console.WriteLine(); PrintSavingsAccountDetails(garysSavingsAccount); Console.WriteLine(); // apply 2 years of interest to the savings accounts acesSavingsAccount.ApplyInterest(2); garysSavingsAccount.ApplyInterest(2); // apply 6 years of interest to Kael kaelsSavingsAccount.ApplyInterest(6); Console.WriteLine("Updated Savings Account Balance After Interest:"); Console.WriteLine(); PrintSavingsAccountDetails(acesSavingsAccount); Console.WriteLine(); PrintSavingsAccountDetails(garysSavingsAccount); Console.WriteLine(); PrintSavingsAccountDetails(kaelsSavingsAccount); Console.WriteLine(); Console.ReadLine(); }