예제 #1
0
 public PortfolioDomainModel(List<StockDomainModel> stocks, Portfolio portfolio)
 {
     Stocks = stocks;
     ID = portfolio.ID;
     Name = portfolio.Name;
     DateCreated = portfolio.DateCreated;
     UpdatePortfolioDollarValue();
     SetWeights();
     CalculateExpectedReturn();
     CalculateVariance(Stocks);
 }
예제 #2
0
파일: Builder.cs 프로젝트: mjheller/Folio
 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;
 }
예제 #3
0
        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);
        }
예제 #4
0
        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();
        }