예제 #1
0
        public async Task <IActionResult> ExecuteSale([Bind("USD,CryptoPrice,AmountToSell,CryptoSymbol")] SellViewModel inSell)
        {
            var user = await _userManager.GetUserAsync(User);

            var transaction = new TransactionModel
            {
                USD               = user.USD,  //the amount of cash available to spend
                BTC               = user.BTC,  //Number of crypto owned
                ETH               = user.ETH,  //Number of crypto owned
                LTC               = user.LTC,  //Number of crypto owned
                DOGE              = user.DOGE, //Number of crypto owned
                CryptoSymbol      = inSell.CryptoSymbol,
                AmountToBuyOrSell = inSell.AmountToSell
            };

            if (_cryptoTransactionService.CanSellCrypto(transaction))
            {
                transaction = _cryptoTransactionService.SellCryptoPerPiece(transaction);

                user.USD  = transaction.USD;
                user.BTC  = transaction.BTC;
                user.ETH  = transaction.ETH;
                user.LTC  = transaction.LTC;
                user.DOGE = transaction.DOGE;
                user.TotalAccountValue = transaction.TotalAccountValue;
                _context.SaveChanges();

                return(RedirectToAction("Wallet", "Crypto"));
            }
            else
            {
                return(RedirectToAction("Wallet", "Crypto"));
            }
        }
예제 #2
0
        public async Task <IActionResult> ExecuteSale([Bind("USD,CryptoPrice,AmountToSell,CryptoSymbol")] SellViewModel inSell)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var transaction = new TransactionModel
            {
                USD               = user.USD,
                BTC               = user.BTC,
                ETH               = user.ETH,
                LTC               = user.LTC,
                DOGE              = user.DOGE,
                CryptoSymbol      = inSell.CryptoSymbol,
                AmountToBuyOrSell = inSell.AmountToSell
            };

            if (_cryptoTransactionService.CanSellCrypto(transaction))
            {
                transaction = _cryptoTransactionService.SellCryptoPerPiece(transaction);

                user.USD  = transaction.USD;
                user.BTC  = transaction.BTC;
                user.ETH  = transaction.ETH;
                user.LTC  = transaction.LTC;
                user.DOGE = transaction.DOGE;
                user.TotalAccountValue = transaction.TotalAccountValue;
                _context.SaveChanges();

                return(RedirectToAction("Wallet", "Crypto"));
            }
            else
            {
                return(RedirectToAction("Wallet", "Crypto"));
            }
        }