public static bool Deposit(DepositWithrawVM transaction) { var account = BankRepository.GetAccount(transaction.AccountNumber); if (account != null) { account.Deposit(transaction.Amount); return(true); } return(false); }
public static bool Withraw(DepositWithrawVM transaction) { var account = BankRepository.GetAccount(transaction.AccountNumber); if ((account.Balance - transaction.Amount) >= 0) { account.Withraw(transaction.Amount); return(true); } return(false); }
public static string DepositFunds(DepositWithrawVM transfer) { var account = FindAccount(transfer.AccountNumber); if (account != null) { account.Balance += transfer.Ammount; return($"{transfer.Ammount}.kr insatta på konto {account.AccountNumber}. Aktuellt Saldo är: {account.Balance}.kr"); } return("Kontot kunde inte hittas."); }
public IActionResult Deposit(DepositWithrawVM obj, string deposit, string withdrawal) { if (!string.IsNullOrEmpty(deposit)) { ViewBag.Message = BankRepository.DepositFunds(obj); } if (!string.IsNullOrEmpty(withdrawal)) { ViewBag.Message = BankRepository.WithdrawFunds(obj); } return(View()); }
public static string WithdrawFunds(DepositWithrawVM transfer) { var account = FindAccount(transfer.AccountNumber); if (account != null) { if (transfer.Ammount <= account.Balance) { account.Balance -= transfer.Ammount; return($"{transfer.Ammount}.kr uttaget från konto {account.AccountNumber}. Aktuellt Saldo är: {account.Balance}.kr"); } return("Ej tillräckligt på kontot."); } return("Kontot kunde inte hittas."); }
public void InsufficinetFundsTest() { CreateCustommer(); var withdrawal = new DepositWithrawVM { AccountNumber = 1002, Ammount = 1001 }; BankRepository.WithdrawFunds(withdrawal); decimal expectedValue = 1000; decimal actualValue = BankRepository.Customers.FirstOrDefault(x => x.Name == "Gustav Cleveman").Accounts.FirstOrDefault().Balance; Assert.Equal(expectedValue, actualValue); }
public void DepositTest() { CreateCustommer(); var deposit = new DepositWithrawVM { AccountNumber = 1002, Ammount = 500 }; BankRepository.DepositFunds(deposit); decimal expectedValue = 1500; decimal actualValue = BankRepository.Customers.FirstOrDefault(x => x.Name == "Gustav Cleveman").Accounts.FirstOrDefault().Balance; Assert.Equal(expectedValue, actualValue); }
public void VerifyNullGuard() { var testAccount = new Account(3, new Customer(), 1000); BankRepository.AddAccount(testAccount); var account = BankRepository.GetAccount(3); var amountToWithraw = 2000; var transaction = new DepositWithrawVM { AccountNumber = account.Id, Amount = amountToWithraw }; var expected = 1000; Bank.Withraw(transaction); var actual = BankRepository.GetAccount(3).Balance; Assert.Equal(expected, actual); }
public void VerifyInsufficientFundsWorks() { var testAccount = new Account(4, new Customer(), 7000); BankRepository.AddAccount(testAccount); var account = BankRepository.GetAccount(4); var amountToWithraw = 8000; var transaction = new DepositWithrawVM { AccountNumber = account.Id, Amount = amountToWithraw }; var expected = 7000; Bank.Withraw(transaction); var actual = BankRepository.GetAccount(4).Balance; Assert.Equal(expected, actual); }
public void VerifyDepositWorks() { var testAccount = new Account(1, new Customer(), 3000); BankRepository.AddAccount(testAccount); var account = BankRepository.GetAccount(1); var amountToDeposit = 3000; var transaction = new DepositWithrawVM { AccountNumber = account.Id, Amount = amountToDeposit }; var expected = account.Balance + amountToDeposit; Bank.Deposit(transaction); var actual = BankRepository.GetAccount(1).Balance; Assert.Equal(expected, actual); }
public IActionResult ProcessForm(DepositWithrawVM form, string deposit, string withraw) { if (ModelState.IsValid) { if (!string.IsNullOrEmpty(deposit)) { if (Bank.Deposit(form)) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "Error! We couldn't find the account."); } } if (!string.IsNullOrEmpty(withraw)) { if (Bank.AccountExists(form.AccountNumber)) { if (Bank.Withraw(form)) { return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(string.Empty, "Error! Insufficient funds."); } } else { ModelState.AddModelError(string.Empty, "Error! We couldn't find the account."); } } } return(View("DepositWithraw")); }