public Trade(InvestmentAccount account, Asset asset, char action) { Action = action; //buy or sell Asset = asset; if (action == 'b') // b for buy { try { asset.WithdrawAsset(account); //Withdraw funds to cover the buy account.AddInvestmentAssets(asset); //Asset bought. Add to account. } catch (InsufficientFundsException) { throw; } } else //we are selling { try { Validator.VerifyAssets(account, asset); //are we trying to sell what we don't have? RemoveTradeAsset(account, asset); asset.DepositAsset(account); //but adds funds gained from sale } catch (InvalidTradeException) { throw; } } }
public InvestmentAccount LoadInvestmentAccount(string accountNumber, TradeDate tradeDate) { InvestmentAccount account = null; using (IDbConnection con = this.GetConnection()) { con.Open(); using (IDbCommand cmd = con.CreateCommand()) { cmd.CommandText = $"{SQL} WHERE a.AccountNumber = @AccountNumber"; cmd.AddParameterWithValue("@TradeDate", tradeDate.Date); cmd.AddParameterWithValue("@AccountNumber", accountNumber); using (IDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { account = this.DecodeRow(reader); } } } } return(account); }
static void Main(string[] args) { var savingsAccount = new SavingsAccount(owner: "Joe Decker", balance: 200); savingsAccount.ShowAccountDetails(); savingsAccount.Withdraw(20); savingsAccount.CheckRemainingBalance(); savingsAccount.Deposit(100); savingsAccount.CheckRemainingBalance(); var loanAccount = new LoanAccount(owner: "John Wright", balance: -1200); loanAccount.ShowAccountDetails(); loanAccount.Deposit(200); loanAccount.CheckRemainingBalance(); var investmentAccount = new InvestmentAccount(owner: "Mike Schwartz", balance: 10000); investmentAccount.ShowAccountDetails(); investmentAccount.Withdraw(2000); investmentAccount.CheckRemainingBalance(); investmentAccount.Deposit(1200); investmentAccount.CheckRemainingBalance(); }
public ActionResult DeleteConfirmed(int id) { InvestmentAccount investmentaccount = db.InvestmentAccounts.Find(id); db.BankAccounts.Remove(investmentaccount); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /InvestmentAccount/Details/5 public ActionResult Details(int id = 0) { InvestmentAccount investmentaccount = db.InvestmentAccounts.Find(id); if (investmentaccount == null) { return(HttpNotFound()); } return(View(investmentaccount)); }
// // GET: /InvestmentAccount/Delete/5 public ActionResult Delete(int id = 0) { InvestmentAccount investmentaccount = (InvestmentAccount)db.BankAccounts.Find(id); if (investmentaccount == null) { return(HttpNotFound()); } return(View(investmentaccount)); }
public static void RunExample() { ShortTermAccountFactory shortTermAccountFactory = new ShortTermAccountFactory(); AbstractAccountFactory abstractAccountFactory = new AbstractAccountFactory(shortTermAccountFactory, "Brian"); BankAccount checkingAccount = abstractAccountFactory.BankAccount; InvestmentAccount investmentAccount = abstractAccountFactory.InvestmentAccount; checkingAccount.Deposit(100); investmentAccount.Deposit(100); }
public void Deposit_GivenInvalidAmount_ShouldThrowException() { // Arrange double startingBalance = 200; double negativeAmount = -100; var investmentAccount = new InvestmentAccount(owner: "Mike Schwartz", balance: startingBalance); // Act, Assert Assert.Throws <ArgumentOutOfRangeException>(() => investmentAccount.Deposit(negativeAmount)); }
public ActionResult DeleteConfirmed(int id) { InvestmentAccount investmentAccount = db.InvestmentAccounts.Find(id); if (investmentAccount.UserId != ViewBag.UserId) { return(RedirectToAction("Unauthorized", "Home")); } db.InvestmentAccounts.Remove(investmentAccount); db.SaveChanges(); return(RedirectToAction("Index")); }
// // GET: /InvestmentAccount/Edit/5 public ActionResult Edit(int id = 0) { InvestmentAccount investmentaccount = db.InvestmentAccounts.Find(id); if (investmentaccount == null) { return(HttpNotFound()); } ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); ViewBag.AccountStateId = new SelectList(db.AccountStates, "AccountStateId", "Description", investmentaccount.AccountStateId); return(View(investmentaccount)); }
public ActionResult Edit(InvestmentAccount investmentaccount) { if (ModelState.IsValid) { db.Entry(investmentaccount).State = EntityState.Modified; investmentaccount.ChangeState(); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AccountStateId = new SelectList(db.AccountStates, "AccountStateId", "Description", investmentaccount.AccountStateId); ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); return(View(investmentaccount)); }
public void CalculateInterestInvestment() { float initialBalance = 200; float expected = 210; Customer customer = new Customer(4, "Allen", "02222222"); InvestmentAccount investmentAccount = new InvestmentAccount(customer, 5, initialBalance, 5, 20); float actual = investmentAccount.CalculateInterest(); Console.WriteLine("actual " + actual); Assert.AreEqual(expected, actual, 0.001); }
public void WithdrawWithValidAmountInvestment() { float initialBalance = 200; float withdrawAmount = 50; float expected = 150; Customer customer = new Customer(4, "Allen", "02222222"); InvestmentAccount investmentAccount = new InvestmentAccount(customer, 5, initialBalance, 5, 20); float actual = investmentAccount.Withdraw(withdrawAmount); Assert.AreEqual(expected, actual); }
public void DepositWithValidAmountInvestment() { float initialBalance = 200; float depositAmount = 50; float expected = 250; Customer customer = new Customer(4, "Allen", "02222222"); InvestmentAccount investmentAccount = new InvestmentAccount(customer, 5, initialBalance, 5, 20); float actual = investmentAccount.Deposit(depositAmount); Assert.AreEqual(expected, actual); }
public ActionResult Create([Bind(Include = "Id,PortfolioId,AccountName,Type,Balance,Currency,WebUrl,Returns,UserName,Password")] InvestmentAccount investmentAccount) { if (ModelState.IsValid) { investmentAccount.UserId = ViewBag.UserId; db.InvestmentAccounts.Add(investmentAccount); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PortfolioId = new SelectList(db.Portfolios.Where(a => a.UserId == investmentAccount.UserId), "PortfolioId", "Name", investmentAccount.PortfolioId); return(View(investmentAccount)); }
public void OpenInvestmentAccount(double balance, double fee, int accountNum, bool isForex) { try { Validator.VerifyIfAccountExists(AccountList, typeof(InvestmentAccount)); InvestmentAccount Investmentacc = new InvestmentAccount(accountNum, balance, fee, isForex); AccountList.Add(Investmentacc); } catch (AccountManagementException accEx) { throw accEx; } }
public ActionResult Edit(InvestmentAccount investmentaccount) { if (ModelState.IsValid) { db.Entry(investmentaccount).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AccountStatusId = new SelectList(db.AccountStatus, "AccountStatusId", "Description", investmentaccount.AccountStatusId); //display fullnam instead of firstname //ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FirstName", investmentaccount.ClientId); ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); return(View(investmentaccount)); }
// // GET: /InvestmentAccount/Edit/5 public ActionResult Edit(int id = 0) { InvestmentAccount investmentaccount = db.InvestmentAccounts.Find(id); if (investmentaccount == null) { return(HttpNotFound()); } ViewBag.AccountStatusId = new SelectList(db.AccountStatus, "AccountStatusId", "Description", investmentaccount.AccountStatusId); //display fullnam instead of firstname //ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FirstName", investmentaccount.ClientId); ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); return(View(investmentaccount)); }
private void btnTotal_Click(object sender, EventArgs e) { SavingsAccount sa = new SavingsAccount(); InvestmentAccount ic = new InvestmentAccount(); sa.Deposit(200.0); ic.Deposit(300.0); TaxManager t = new TaxManager(); t.Accumulates(sa); t.Accumulates(ic); MessageBox.Show("Total de taxas: " + t.Total); }
public ActionResult Edit([Bind(Include = "Id,PortfolioId,AccountName,Type,Balance,Currency,WebUrl,Returns,UserName,Password")] InvestmentAccount investmentAccount) { if (investmentAccount.UserId != ViewBag.UserId) { return(RedirectToAction("Unauthorized", "Home")); } if (ModelState.IsValid) { db.Entry(investmentAccount).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PortfolioId = new SelectList(db.Portfolios.Where(a => a.UserId == investmentAccount.UserId), "PortfolioId", "Name", investmentAccount.PortfolioId); return(View(investmentAccount)); }
public ActionResult Create(InvestmentAccount investmentaccount) { investmentaccount.SetNextAccountNumber(); if (ModelState.IsValid) { db.BankAccounts.Add(investmentaccount); db.SaveChanges(); investmentaccount.ChangeState(); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AccountStateId = new SelectList(db.AccountStates, "AccountStateId", "Description", investmentaccount.AccountStateId); ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); return(View(investmentaccount)); }
public void Deposit_GivenValidAmount_ShouldUpdateBalance() { // Arrange double startingBalance = 1000; double depositAmount = 1200; double expected = startingBalance + depositAmount; var investmentAccount = new InvestmentAccount(owner: "Mike Schwartz", balance: startingBalance); // Act investmentAccount.Deposit(depositAmount); // Assert double actual = investmentAccount.Balance; Assert.Equal(expected, actual); }
public void Withdraw_GivenValidAmount_ShouldUpdateBalance() { // Arrange double startingBalance = 10000; double withdrawalAmount = 2000; double expected = startingBalance - (withdrawalAmount + (withdrawalAmount * InvestmentAccount.MANAGEMENT_FEE)); var investmentAccount = new InvestmentAccount(owner: "Mike Schwartz", balance: startingBalance); // Act investmentAccount.Withdraw(withdrawalAmount); // Assert double actual = investmentAccount.Balance; Assert.Equal(expected, actual); }
public ActionResult Create(InvestmentAccount investmentaccount) { //calling the appropriate SetNext method investmentaccount.SetNextAccountNumber(); if (ModelState.IsValid) { db.BankAccounts.Add(investmentaccount); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AccountStatusId = new SelectList(db.AccountStatus, "AccountStatusId", "Description", investmentaccount.AccountStatusId); //display fullnam instead of firstname //ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FirstName", investmentaccount.ClientId); ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); return(View(investmentaccount)); }
public ActionResult Create(InvestmentAccount investmentaccount) { //This code has been modified if (ModelState.IsValid) { //Setting the investment account number to the next available one when creating a new investment account investmentaccount.SetNextAccountNumber(); db.BankAccounts.Add(investmentaccount); investmentaccount.ChangeState(); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AccountStateId = new SelectList(db.AccountStates, "AccountStateId", "Description", investmentaccount.AccountStateId); ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); return(View(investmentaccount)); }
// GET: Investments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InvestmentAccount investmentAccount = db.InvestmentAccounts.Find(id); if (investmentAccount == null) { return(HttpNotFound()); } if (investmentAccount.UserId != ViewBag.UserId) { return(RedirectToAction("Unauthorized", "Home")); } return(View(investmentAccount)); }
//tests deposit function with a invaild amount public void DepositWithInvalidAmountInvestment() { float initialBalance = 200; float depositAmount = -50; Customer customer = new Customer(4, "Allen", "02222222"); InvestmentAccount investmentAccount = new InvestmentAccount(customer, 5, initialBalance, 5, 20); try { investmentAccount.Deposit(depositAmount); } catch (ArgumentOutOfRangeException) { return; } Assert.Fail(); }
public void WithdrawWithLessThanZeroInvestment() { float initialBalance = 200; float withdrawAmount = -10; Customer customer = new Customer(4, "Allen", "02222222"); InvestmentAccount investmentAccount = new InvestmentAccount(customer, 5, initialBalance, 5, 20); try { investmentAccount.Withdraw(withdrawAmount); } catch (ArgumentOutOfRangeException) { return; } Assert.Fail(); }
// GET: Investments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } InvestmentAccount investmentAccount = db.InvestmentAccounts.Find(id); if (investmentAccount == null) { return(HttpNotFound()); } if (investmentAccount.UserId != ViewBag.UserId) { return(RedirectToAction("Unauthorized", "Home")); } ViewBag.PortfolioId = new SelectList(db.Portfolios.Where(a => a.UserId == investmentAccount.UserId), "PortfolioId", "Name", investmentAccount.PortfolioId); return(View(investmentAccount)); }
public ActionResult Create(InvestmentAccount investmentaccount) { //Calling method for auto increment. investmentaccount.SetNextAccountNumber(); if (ModelState.IsValid) { db.BankAccounts.Add(investmentaccount); db.SaveChanges(); //Changes the accountstate if the account requirements are not fullfilled investmentaccount.ChangeState(); db.SaveChanges(); return(RedirectToAction("Index")); } //Displays the fullname for the client ViewBag.ClientId = new SelectList(db.Clients, "ClientId", "FullName", investmentaccount.ClientId); ViewBag.AccountStateId = new SelectList(db.AccountStates, "AccountStateId", "Description", investmentaccount.AccountStateId); return(View(investmentaccount)); }