public ActionResult BuyPriceDesc(AmericanCenturyBuysViewModel AmericanCenturyTransaction) { var excludeShortTermTransactions = AmericanCenturyTransaction.ExcludeShortTermTransactions; var context = new InvestContext(); var AmericanCenturyTransactions = GetAmericanCenturyLongTermTransactionsList(excludeShortTermTransactions); return View(AmericanCenturyTransactions); }
private static AmericanCenturyBuysViewModel BuildTransactionObjects(List<Invest.Domain.Models.AmericanCenturyTransaction> transactions, bool seperateReinvest) { var nav = GetLatestTickersNav("TWCUX"); var AmericanCenturyTransactions = new AmericanCenturyBuysViewModel { Nav = nav.ToString("C"), SecurityTicker = "TWCUX", SecurityName = "American Century Ultra", Transactions = new List<AmericanCenturyBuyViewModel>() }; decimal totalInvested = 0; decimal totalReinvested = 0; decimal totalShares = 0; decimal currentValue = 0; decimal totalValue = 0; decimal gain = 0; foreach (var transaction in transactions) { var shares = transaction.AmericanCenturyBuy.Shares.Value; var amountInvested = transaction.AmericanCenturyBuy.Amount.Value; if (transaction.AmericanCenturyBuy.TranType == "Buy" || !seperateReinvest) { totalInvested += amountInvested; } else { totalReinvested += amountInvested; } totalShares += shares; currentValue = shares * nav; totalValue += currentValue; gain = currentValue - transaction.AmericanCenturyBuy.Amount.Value; var AmericanCenturyTransaction = new AmericanCenturyBuyViewModel(); AmericanCenturyTransaction.Id = transaction.AmericanCenturyBuy.Id; AmericanCenturyTransaction.BuyDate = transaction.AmericanCenturyBuy.Date.ToShortDateString(); if (transaction.AmericanCenturyBuy.TranType == "Buy" || !seperateReinvest) { AmericanCenturyTransaction.AmountInvested = amountInvested.ToString("C"); } else { AmericanCenturyTransaction.AmountReinvested = amountInvested.ToString("C"); } AmericanCenturyTransaction.BuyPrice = transaction.AmericanCenturyBuy.Nav.Value.ToString("C"); AmericanCenturyTransaction.Shares = transaction.AmericanCenturyBuy.Shares.Value.ToString("F3"); AmericanCenturyTransaction.CurrentValue = currentValue.ToString("C"); AmericanCenturyTransaction.Gain = gain.ToString("C"); AmericanCenturyTransaction.TranType = transaction.AmericanCenturyBuy.TranType.ToString(); AmericanCenturyTransaction.TotalShares = totalShares.ToString("F3"); AmericanCenturyTransaction.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; } AmericanCenturyTransactions.Transactions.Add(AmericanCenturyTransaction); } AmericanCenturyTransactions.TotalInvested = totalInvested.ToString("C"); AmericanCenturyTransactions.TotalReinvested = totalReinvested.ToString("C"); AmericanCenturyTransactions.TotalShares = totalShares.ToString("F3"); AmericanCenturyTransactions.TotalValue = totalValue.ToString("C"); return AmericanCenturyTransactions; }