public ActionResult AddPurchase(AddPurchaseTransactionVm addPurchaseTransactionVm)
        {
            if (ModelState.IsValid)
            {
                int stockTransactionId = PurchaseTransactionService.CreateStockPurchase(addPurchaseTransactionVm);

                if (stockTransactionId > 0)
                {
                    this.FlashSuccess("Successfully created the stock transaction.", "PurchaseDetails", "StockTransactions");
                    return RedirectToAction("PurchaseDetails", "StockTransactions", new { area = "", id = stockTransactionId });
                }
                this.FlashError("Could not create the stock transaction. Please try again.", "AddPurchase", "StockTransactions");
            }

            var brokerageAccountList = BrokerageAccountService.GetBrokerageAccountListForActiveUser();
            ViewBag.BrokerageAccountId = new SelectList(brokerageAccountList, "Id", "Title", addPurchaseTransactionVm.BrokerageAccountId);

            var stockList = StockService.GetStockList();
            ViewBag.SecurityId = new SelectList(stockList, "Id", "Title", addPurchaseTransactionVm.SecurityId);

            return View();
        }
        public int CreateStockPurchase(AddPurchaseTransactionVm addPurchaseTransactionVm)
        {
            var purchaseTransaction = new PurchaseTransaction()
            {
                BrokerageAccountId = addPurchaseTransactionVm.BrokerageAccountId,
                Commission = addPurchaseTransactionVm.Commission,
                SecurityId = addPurchaseTransactionVm.SecurityId,
                ShareQuantity = addPurchaseTransactionVm.ShareQuantity,
                UnitPrice = addPurchaseTransactionVm.UnitPrice,
                TransactionDate = addPurchaseTransactionVm.TransactionDate,
                ClosedShares = 0,
                RemainingShares = addPurchaseTransactionVm.ShareQuantity,
                PositionClosedStatus = false
            };

            DbOperationStatus opStatus = PurchaseTransactionRepository.InsertPurchaseTransaction(purchaseTransaction);
            if (opStatus.OperationSuccessStatus)
            {
                return opStatus.AffectedIndices.First();
            }
            return -1;
        }