public ActionResult Deposit(int id, IFormCollection collection) { BankTransaction trans = null; try { string result = ""; string acctNumber = collection["SourceAccountNumber"].ToString(); string transAmt = collection["TransactionAmount"].ToString(); string transType = collection["TransactionType"].ToString(); string loginName = ""; trans = new BankTransaction() { SourceBankAccountId = id, SourceAccountNumber = acctNumber, TransactionType = transType, TransactionAmount = Convert.ToDouble(transAmt), TransactionDate = DateTime.UtcNow }; var login = HttpContext.Session.GetString("loginName"); if (login != null) { ViewBag.LoginName = login.ToString(); } if (!string.IsNullOrEmpty(acctNumber) && !string.IsNullOrEmpty(transAmt) && !string.IsNullOrEmpty(transType)) { result = rep.ProcessBankTransaction(trans); } else if (string.IsNullOrEmpty(acctNumber) || string.IsNullOrEmpty(transAmt) || string.IsNullOrEmpty(transType)) { result = "Account Number and Transaction Amount must not be empty"; } if (result.Contains("Successfull")) { _loginName = HttpContext.Session.GetString("loginName"); return(RedirectToAction("Index", new { loginName = _loginName })); } else { ViewBag.Message = result; return(View(trans)); } } catch (Exception ex) { ViewBag.Message = ex.Message; return(View(trans)); } }
public void TestRepProcessBankTransactionUsingDeposit() { string expectedSourceAcctNumber = "20191000600123"; double transactionAmt = 2; //Get values prior to test BankAccount priorBankAcct = _dataLib.GetBankAccountByAccountNumber(expectedSourceAcctNumber); double expectedBalance = priorBankAcct.Balance + transactionAmt; BankTransaction expectedTrans = GenerateBankTransaction(expectedSourceAcctNumber, "", transactionAmt, "Deposit"); _repository.ProcessBankTransaction(expectedTrans); //Get values after test BankAccount currentBankAcct = _dataLib.GetBankAccountByAccountNumber(expectedSourceAcctNumber); Assert.IsNotNull(priorBankAcct); Assert.IsNotNull(currentBankAcct); Assert.AreEqual(expectedBalance, currentBankAcct.Balance); }