public ActionResult Buy(InvestmentViewModel investment) { if (!ModelState.IsValid) { return(View("InvestmentForm", investment)); } var currentInvestment = _unitOfWork.Investment.GetInvestment(investment); var account = _unitOfWork.BankAccount.GetBankAccountById(investment.AccountId); var company = _unitOfWork.Company.GetCompanyById(int.Parse(investment.CompanyId)); Transaction transaction; if (account == null) { return(HttpNotFound()); } if (currentInvestment == null) { var newInvestment = new Investment(account, company); newInvestment.CalculateNewInvestmentAmount(investment.SharePrice, investment.ShareQuantity); newInvestment.DecreaseInvestmentCostToBankAccount(account); //account.IncreaseBankAccountBalance(investmentAmount); _unitOfWork.Investment.AddInvestment(newInvestment); transaction = _log.LogTransaction(TransactionType.Buy, newInvestment); } else { currentInvestment.CalCurrentInvestmentAmountAndShareQuantity(investment.SharePrice, investment.ShareQuantity, investment.Type); account.DecreaseBankAccountBalance(investment.SharePrice * investment.ShareQuantity); transaction = _log.LogTransaction(TransactionType.Buy, currentInvestment); } if (!account.CheckBalanceGreaterThanZero()) { return(Json(new { success = false, responseText = "Account Balance Too Low " }, JsonRequestBehavior.AllowGet)); } _unitOfWork.Transaction.AddTransaction(transaction); _unitOfWork.Complete(); return(Json(new { success = true, responseText = "Share Purchase Was Successfull" }, JsonRequestBehavior.AllowGet)); // var viewModel = new InvestmentViewModel(currentInvestment) {Type = TransactionType.Buy}; // return View("InvestmentForm", investment); }