Beispiel #1
0
            private void ConvertMoney()
            {
                var    firstWallet  = ChooseFirstWallet();
                var    secondWallet = ChooseSecondWallet();
                double currency1    = 0;
                double currency2    = 0;
                double convertedSum;


                if (firstWallet == secondWallet)
                {
                    throw new ArgumentException("You cannot convert the same currency.");
                }

                Console.WriteLine("Enter the sum: ");
                var userSum = Console.ReadLine();

                if (!double.TryParse(userSum, out double result))
                {
                    Console.WriteLine("You can enter only numbers.");
                }
                else if (result <= 0)
                {
                    Console.WriteLine("The sum cannot be under 0.");
                }
                else
                {
                    firstWallet.ConvertFrom(ref result);
                }

                foreach (var x in CurrencyRate)
                {
                    if (x.Key.Contains(firstWallet.Name()))
                    {
                        currency1 = x.Value;
                    }
                }

                foreach (var x in CurrencyRate)
                {
                    if (x.Key.Contains(secondWallet.Name()))
                    {
                        currency2 = x.Value;
                    }
                }

                convertedSum = CurrencyRate.ElementAt(0).Value / currency1 * result * currency2;

                secondWallet.ConvertTo(ref convertedSum);
            }