public void Bet() { decimal amount; string currency; SetAmountAndCurrency(out amount, out currency); try { ActivePlayer.Withdraw(amount, currency); var price = BetService.Bet(amount); if (price == 0) { Console.WriteLine("You lose."); } else { Console.WriteLine($"You won {price} {currency}"); ActivePlayer.Deposit(price, currency); } } catch (InvalidOperationException) { throw new InvalidOperationException("There is insufficient funds on your account."); } catch (NotSupportedException) { throw new NotSupportedException("Invalid currency"); } }
private void Withdraw() { decimal amount; string currency; SetAmountAndCurrency(out amount, out currency); try { if (currency != "USD" && currency != "EUR" && currency != "UAH") { throw new NotSupportedException(nameof(currency)); } PaymentService.StartWithdrawal(amount, currency); ActivePlayer.Withdraw(amount, currency); } catch (InvalidOperationException) { throw new InvalidOperationException("There is insufficient funds on your account."); } catch (NotSupportedException) { throw new NotSupportedException("Failed. Invalid currency."); } catch (LimitExceededException) { throw; } catch (PaymentServiceException) { throw; } catch (InsufficientFundsException) { throw; } catch (Exception) { throw; } try { Account.Withdraw(amount, currency); Console.WriteLine("Success!"); } catch (InvalidOperationException) { ActivePlayer.Deposit(amount, currency); throw new InvalidOperationException("There is some problem on the platform side. Please try it later."); } }
void Deposit() { Console.Clear(); string currency; double amount; do { Console.Write("Enter currency->"); currency = Console.ReadLine(); }while (currency != "USD" && currency != "EUR" && currency != "UAH"); do { Console.Write("Enter amount->"); }while (!double.TryParse(Console.ReadLine(), out amount)); try { PaymentService.Account = ActivePlayer.Account; PaymentService.StartDeposit(Convert.ToDecimal(amount), currency); ActivePlayer.Deposit(Math.Round(Convert.ToDecimal(amount), 2), currency); Account.Deposit(Math.Round(Convert.ToDecimal(amount), 2), currency); PaymentService.SubmitTransaction(); } catch (InsufficientFundsException e) { Console.WriteLine(e.Message); Console.ReadKey(); } catch (LimitExceededException e) { Console.WriteLine(e.Message); Console.ReadKey(); } catch (PaymentServiceException e) { Console.WriteLine(e.Message); Console.ReadKey(); } catch (InvalidOperationException e) { Console.WriteLine(e.Message); Console.ReadLine(); } }
private void Deposit() { decimal amount; string currency; SetAmountAndCurrency(out amount, out currency); try { if (currency != "USD" && currency != "EUR" && currency != "UAH") { throw new NotSupportedException(nameof(currency)); } PaymentService.StartDeposit(amount, currency); Account.Deposit(amount, currency); ActivePlayer.Deposit(amount, currency); Console.WriteLine("Success!"); } catch (NotSupportedException) { throw new NotSupportedException("Failed. Invalid currency."); } catch (InvalidCastException) { throw new InvalidCastException("Amount must be raither than 0."); } catch (LimitExceededException) { throw; } catch (PaymentServiceException) { throw; } catch (InsufficientFundsException) { throw; } catch (Exception) { throw; } }