public async Task <IActionResult> Withdraw(WithdrawViewModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } bool send; ViewData["Message"] = ""; var balance = await _blockchainRepository.GetBalance(NETWORK_TYPE.TESTNET, user.Address); ASSET_NAME a = model.Asset == 1 ? ASSET_NAME.GAS : ASSET_NAME.NEO; double b = model.Asset == 1 ? balance.GAS : balance.NEO; if (b < model.Amount) { ViewData["Message"] = "insufficient funds"; return(View(model)); } send = await _blockchainRepository.SendAsset(NETWORK_TYPE.TESTNET, user.Wif, a, model.Address, model.Amount); if (send) { ViewData["Message"] = "Success"; return(View(model)); } ViewData["Message"] = "Failed to withdraw"; } // If we got this far, something failed, redisplay form return(View(model)); }