public async Task <IActionResult> Create([Bind("Id,Date,StockId,Open,High,Low,Close,LastClose,Volume,Amount,Change,ChangePercentage,ContinueTrend,TurnoverRate,CreatedOn,ModifiedOn")] StockPerf stockPerf) { if (ModelState.IsValid) { _context.Add(stockPerf); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stockPerf)); }
public async Task <IActionResult> Create([Bind("Id,Name,StartDate,BenchmarkId,Description,CreatedOn,ModifiedOn")] Strategy strategy) { if (ModelState.IsValid) { _context.Add(strategy); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(strategy)); }
public async Task <IActionResult> Create([Bind("Id,StrategyId,StockId,TXDate,TXPrice,Shares,Amount")] Statement statement) { if (ModelState.IsValid) { _context.Add(statement); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["StrategyId"] = new SelectList(_context.Strategys, "Id", "Id", statement.StrategyId); return(View(statement)); }
public async Task <IActionResult> Create([Bind("Id,StrategyId,StockId,CreatedOn,ModifiedOn")] StrategySubject strategySubject) { if (ModelState.IsValid) { _context.Add(strategySubject); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["StrategyId"] = new SelectList(_context.Strategys, "Id", "Id", strategySubject.StrategyId); return(View(strategySubject)); }
public async Task <IActionResult> Create([Bind("Id,Name,BriefName,Symbol,Market,Price,Date,Status,Type")] StockInfo stockInfo) { if (ModelState.IsValid) { string id = string.Format("{0}{1}", stockInfo.Market, stockInfo.Symbol); StockInfo exist = _context.StockInfos.Find(id); if (exist != null) { return(View(stockInfo)); } stockInfo.Id = id; stockInfo.CreatedOn = stockInfo.ModifiedOn = DateTime.Now; _context.Add(stockInfo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(stockInfo)); }
public async Task <IActionResult> ConfirmBuy([Bind("ID,NrOfTradeItems,StockSymbol")] Order trade) { var identity = User.Identity as System.Security.Claims.ClaimsIdentity; _currentUser = identity.FindFirst(System.Security.Claims.ClaimTypes.NameIdentifier)?.Value; trade.TradeDate = DateTime.Now; trade.objectId = _currentUser; trade.OrderStatus = "open"; trade.Action = "buy"; if (ModelState.IsValid) { _context.Add(trade); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Orders))); } return(View()); }
public async Task <IActionResult> Create([Bind("Id,Date,Benchmark,BaseAmount,Name")] MasterPortfolio masterPortfolio, string holdings) { if (masterPortfolio.Benchmark == null || !masterPortfolio.BaseAmount.HasValue) { return(View(masterPortfolio)); } StockInfo si = _context.StockInfos.Find(masterPortfolio.Benchmark); if (si == null) { return(View(masterPortfolio)); } if (masterPortfolio.BaseAmount.HasValue) { masterPortfolio.BaseAmount = 100000; } if (ModelState.IsValid) { //masterPortfolio.Name = string.Format("{0}-{1}",si.Name,masterPortfolio.Date.ToString("yyyyMMdd")); masterPortfolio.Status = MasterPortfolioStatus.Pending; masterPortfolio.CreatedOn = masterPortfolio.ModifiedOn = DateTime.Now; _context.Add(masterPortfolio); await _context.SaveChangesAsync(); if (!String.IsNullOrEmpty(holdings)) { string[] holdingVals = holdings.Split(new char[] { ',', ';' }); List <PortfolioHolding> holdingList = new List <PortfolioHolding>(); foreach (string val in holdingVals) { if (String.IsNullOrEmpty(val)) { continue; } PortfolioHolding ph = new PortfolioHolding() { MasterPortfolioId = masterPortfolio.Id, StockId = val.Split(new char[] { '_' })[0], }; holdingList.Add(ph); } foreach (PortfolioHolding ph in holdingList) { ph.Weight = 100.0m / holdingList.Count; si = _context.StockInfos.Find(ph.StockId); if (si == null) { return(View(masterPortfolio)); } string key = String.Format("{0}_{1}", si.Id, masterPortfolio.Date.ToString("yyyyMMdd")); StockPerf price = _context.StockPerfs.Find(key); if (price == null) { return(View(masterPortfolio)); } ph.ModifiedOn = ph.CreatedOn = DateTime.Now; ph.Shares = (int)Math.Floor(ph.Weight.Value * masterPortfolio.BaseAmount.Value / price.Close.Value / 100 / 100) * 100;//整手 ph.ActualWeight = 100 * ph.Shares * price.Close.Value / masterPortfolio.BaseAmount; _context.Add(ph); } } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(masterPortfolio)); }