コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,UserId,SymbolId,Quantity,Price,Action,CreationDate,Comment,Status,Reserved")] Trade trade)
        {
            if (ModelState.IsValid)
            {
                trade.UserId       = _userManager.GetUserId(HttpContext.User);
                trade.CreationDate = DateTime.Now;
                trade.Status       = TradeStatus.Approved;
                _context.Add(trade);
                await _context.SaveChangesAsync();

                //creating a transaction to pay or get paid for the trade. can be set status too? but
                // right now all will be set to approved because there is try-catch on all transactions and trade
                Transaction transaction = new Transaction();
                transaction = await _tradeHelper.createTradeTransaction(trade);

                await _tradeHelper.updateUserCashBalance(transaction);

                _logger.LogWarning("Before Wealth creation" + transaction.TransactionType);
                await _tradeHelper.createWealth(transaction);

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["SymbolId"] = new SelectList(_context.TickerSymbols.Where(s => s.isEnabled == true), "Id", "Symbol", trade.SymbolId);
            return(View(trade));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("Id,UserId,TradeId,TransType,FromAccount,ToAccount,TotalAmount,Comment,TimeStamp,Reconciled")] Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                transaction.UserId       = _userManager.GetUserId(HttpContext.User);
                transaction.CreationDate = DateTime.Now;
                transaction.Reconciled   = true;
                _context.Add(transaction);
                await _context.SaveChangesAsync();

                bool result = await _tradeHelperService.updateUserCashBalance(transaction);

                if (!result)
                {
                    ViewData["error"] = "Transaction Faild.";
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(transaction));
        }