Esempio n. 1
0
        public override async Task ExecuteAsync(object parameter)
        {
            _buyViewModel.StatusMessage = string.Empty;
            _buyViewModel.ErrorMessage  = string.Empty;

            try
            {
                string  symbol  = _buyViewModel.Symbol;
                int     shares  = _buyViewModel.SharesToBuy;
                Account account = await _buyStockService.BuyStock(_accountStroe.CurrentAccount, symbol, shares);

                _accountStroe.CurrentAccount = account;

                _buyViewModel.StatusMessage = $"Successfully purchased {shares} shares of {symbol}.";
            }
            catch (InsufficientFundsException)
            {
                _buyViewModel.ErrorMessage = "Account has insufficient funds. Please transfer more money into your account.";
            }
            catch (InvalidSymbolException)
            {
                _buyViewModel.ErrorMessage = "Symbol does not exist.";
            }
            catch (Exception)
            {
                _buyViewModel.ErrorMessage = "Transaction failed.";
            }
        }
Esempio n. 2
0
 private async void BuyStockCmd()
 {
     Account user = await _buyStockService.BuyStock(new Account()
     {
         Id = 1,
         Balance = 500,
         AssetTransactions = new List<AssetTransaction>()
     }, this.Symbol, this.ShareToBuy);
 }
Esempio n. 3
0
        public async void Execute(object parameter)
        {
            try
            {
                Account account = await _buyStockService.BuyStock(_accountStore.CurrentAccount, _buyViewModel.Symbol, _buyViewModel.SharesToBuy);

                _accountStore.CurrentAccount = account;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Esempio n. 4
0
 public async void Execute(object parameter)
 {
     try
     {
         var account = await _buyStockService.BuyStock(new Account
         {
             Id                = 1,
             Balance           = 500,
             AssetTransactions = new List <AssetTransaction>()
         }, _buyViewModel.Symbol, _buyViewModel.SharesToBuy).ConfigureAwait(false);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Esempio n. 5
0
 public async void Execute(object parameter)
 {
     try
     {
         await _buyStockService.BuyStock(new Domain.Models.Account
         {
             id                = 12,
             Balance           = 700,
             AssetTransactions = new List <AssetTransaction>(),
         }, _buyViewModel.Symbol, _buyViewModel.SharesToBuy);
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
Esempio n. 6
0
        public async void Execute(object parameter)
        {
            try
            {
                //TODO: replace this with an injected object in the future
                var buyer = new Account()
                {
                    Id = 3,
                    AssetTransactions = new List <AssetTransaction>(),
                    Balance           = 500
                };

                Account account = await _buyStockService.BuyStock(buyer, _buyViewModel.Symbol, _buyViewModel.SharesToBuy);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }