public PortfolioDomainModel(List<StockDomainModel> stocks, Portfolio portfolio) { Stocks = stocks; ID = portfolio.ID; Name = portfolio.Name; DateCreated = portfolio.DateCreated; UpdatePortfolioDollarValue(); SetWeights(); CalculateExpectedReturn(); CalculateVariance(Stocks); }
public PortfolioDomainModel GetPortfolioDomainModel(Portfolio portfolio) { IEnumerable<string> symbols = portfolio.PortfolioAssets.Select(a => a.AssetSymbol); List<Stock> stocks = _context.Stock .Where(s => symbols.Contains(s.Symbol)).ToList(); List<StockDomainModel> stockDomainModels = new List<StockDomainModel>(); Parallel.For(0, stocks.Count(), i => { int amountOwned = portfolio.PortfolioAssets.Single(a => a.AssetSymbol == stocks[i].Symbol).NumberOfAssetOwned; stockDomainModels.Add(new StockDomainModel(stocks[i], amountOwned)); }); PortfolioDomainModel output = new PortfolioDomainModel(stockDomainModels, portfolio); return output; }
public async Task<IActionResult> Edit(Portfolio portfolio) { if (ModelState.IsValid) { _context.Update(portfolio); await _context.SaveChangesAsync(); return RedirectToAction("Index"); } HttpContext.Session.Remove("selected_port_viewmodel"); return View(portfolio); }
public async Task<IActionResult> Create(Portfolio portfolio) { if (ModelState.IsValid) { ApplicationUser user = await _userManager.FindByIdAsync(HttpContext.User.GetUserId()); portfolio.User = user; portfolio.DateCreated = DateTime.Now; _context.Portfolio.Add(portfolio); await _context.SaveChangesAsync(); return RedirectToAction("AddStock", portfolio); } return View(); }