public async Task <Account> Invest(Account investor, string currency, int quantity) { double price = await _cryptoPriceService.GetPrice(currency); if (price * quantity > investor.Balance) { throw new Exception("Insufficient Funds!"); } ; CryptoInvestment cryptoInvestment = new CryptoInvestment() { Account = investor, CryptoCurrencyInvest = new CryptoCurrencyInvest() { Price = price, Ticker = currency, }, DateInvested = DateTime.Now, Quantity = quantity, IsPurchase = true }; investor.CryptoInvestments.Add(cryptoInvestment); investor.Balance -= price * quantity; await _accountService.Update(investor.Id, investor); return(investor); }
public async void Execute(object parameter) { try { double price = await _cryptoPriceService.GetPrice(_investViewModel.Currency); _investViewModel.Price = price; } catch (Exception e) { MessageBox.Show(e.Message); } }