public BuyAndHoldRawTransactionsViewModel BuildRawTransactionObjects(List<BuyAndHoldRawTransactionDto> transactions, NavDto nav, bool seperateReinvest)
        {
            var currentShareValue = nav.Nav; //GetLatestTickersNav("TWCUX");

            var viewModel = new BuyAndHoldRawTransactionsViewModel
            {
                Nav = currentShareValue.ToString("C"),
                SecurityTicker = "TWCUX",
                SecurityName = "American Century Ultra",
                Transactions = new List<BuyAndHoldRawTransactionViewModel>()
            };
            decimal totalInvested = 0;
            decimal totalReinvested = 0;
            decimal totalShares = 0;
            decimal currentValue = 0;
            decimal totalValue = 0;
            decimal gain = 0;
            foreach (var transaction in transactions)
            {
                var buyAndHoldTransaction = new BuyAndHoldRawTransactionViewModel();

                var shares = transaction.NumberShares;
                var amountInvested = transaction.AmountInvested.HasValue ? transaction.AmountInvested.Value : 0;

                if (transaction.TransactionType == "Buy" || !seperateReinvest)
                {
                    totalInvested += amountInvested;
                }
                else
                {
                    totalReinvested += amountInvested;
                }

                var _shares = shares.HasValue ? decimal.Parse(shares.Value.ToString()) : 0;

                if (_shares != 0)
                {
                    totalShares += _shares;
                    currentValue = _shares * currentShareValue;
                    totalValue += currentValue;
                    gain = currentValue - amountInvested;
                    //profit = currentValue - amountInvested;
                }

                buyAndHoldTransaction.Id = transaction.Id;
                //var sellTransaction = transaction.BuyAndHoldSellTransaction;
                //var originalTransaction = transaction.BuyAndHoldOriginalTransaction;

                //if (originalTransaction != null)
                //{
                //    var originalTransactionAmountInvested = originalTransaction.AmountInvested.HasValue ? originalTransaction.AmountInvested.Value : 0;

                //    buyAndHoldTransaction.OriginalTransaction = new BuyAndHoldTransactionViewModel();
                //    buyAndHoldTransaction.OriginalTransaction.Type = originalTransaction.Type + " [" + originalTransaction.OriginalSymbol.ToUpper() + "]";
                //    buyAndHoldTransaction.OriginalTransaction.Id = originalTransaction.id;
                //    buyAndHoldTransaction.OriginalTransaction.AmountInvested = originalTransactionAmountInvested.ToString("C");
                //}

                //if (sellTransaction != null)
                //{
                //    buyAndHoldTransaction.SellDate = sellTransaction.TransactionDate.Value.ToShortDateString();
                //    buyAndHoldTransaction.SellPrice = sellTransaction.BuyPrice.HasValue ? sellTransaction.BuyPrice.Value.ToString("C") : "";
                //    buyAndHoldTransaction.Proceeds = sellTransaction.AmountInvested.HasValue ? sellTransaction.AmountInvested.Value.ToString("C") : "";
                //    buyAndHoldTransaction.Profit = ((sellTransaction.AmountInvested.HasValue ? sellTransaction.AmountInvested.Value : 0) - amountInvested).ToString("C");
                //}
                buyAndHoldTransaction.BuyDate = transaction.TransactionDate.Value.ToShortDateString();
                if (transaction.TransactionType == "Buy" || !seperateReinvest)
                {
                    buyAndHoldTransaction.AmountInvested = amountInvested.ToString("C");
                }
                else if (amountInvested != 0)
                {
                    buyAndHoldTransaction.AmountReinvested = amountInvested.ToString("C");
                }
                buyAndHoldTransaction.DividendAmount = transaction.DividendAmount.HasValue ? transaction.DividendAmount.Value.ToString("C") : "";
                buyAndHoldTransaction.BuyPrice = transaction.BuyPrice.HasValue ? transaction.BuyPrice.Value.ToString("C") : "";
                buyAndHoldTransaction.NumberShares = transaction.NumberShares.HasValue ? transaction.NumberShares.Value.ToString("F3") : "";
                if (transaction.NumberShares.HasValue)
                {
                    buyAndHoldTransaction.CurrentValue = currentValue.ToString("C");
                }
                buyAndHoldTransaction.IsGainNegative = gain < 0;
                buyAndHoldTransaction.Gain = gain.ToString("C");
                buyAndHoldTransaction.TransactionType = transaction.TransactionType;
                buyAndHoldTransaction.TotalShares = double.Parse(totalShares.ToString("F3"));
                buyAndHoldTransaction.TotalValue = totalValue.ToString("C");

                //if (transaction.AmericanCenturySell != null)
                //{
                //    var sellPrice = transaction.AmericanCenturySell.SellPrice;
                //    var proceeds = shares * sellPrice;

                //    AmericanCenturyTransaction.SellDate = transaction.AmericanCenturySell.SellDate.Date.ToShortDateString();
                //    AmericanCenturyTransaction.SellPrice = transaction.AmericanCenturySell.SellPrice.ToString("C");
                //    AmericanCenturyTransaction.Proceeds = proceeds.ToString("C");
                //    AmericanCenturyTransaction.Profit = (proceeds - amountInvested).ToString("C");
                //    AmericanCenturyTransaction.CurrentValue = null;
                //    AmericanCenturyTransaction.Gain = null;
                //}

                viewModel.Transactions.Add(buyAndHoldTransaction);
            }
            viewModel.TotalInvested = totalInvested.ToString("C");
            viewModel.TotalReinvested = totalReinvested.ToString("C");
            viewModel.TotalShares = totalShares.ToString("F3");
            viewModel.TotalValue = totalValue.ToString("C");
            return viewModel;
        }
 public ActionResult RawTransactions(string id = "")
 {
     var security = new SecurityDto();
     var nav = new NavDto();
     var viewModel = new BuyAndHoldRawTransactionsViewModel();
     int i = 0;
     if (int.TryParse(id, out i))
     {
         security = _securityService.GetSecurityById(i);
         nav = _navService.GetTicker(security.TickerSymbol);
         viewModel = GetBuyAndHoldRawTransactionList(i.ToString(), nav);
     }
     else {
         security = _securityService.GetSecurityBySymbol(id);
         nav = _navService.GetTicker(security.TickerSymbol);
         viewModel = GetBuyAndHoldRawTransactionList(id, nav);
     }
     viewModel.SecurityTicker = security.TickerSymbol;
     viewModel.SecurityName = security.CompanyName;
     viewModel.Nav = nav.Nav.ToString("C");
     viewModel.NavDate = nav.Date.ToShortDateString();
     return View(viewModel);
 }