Exemple #1
0
        public static async Task MainMenuAsync(RatesRepository rates)
        {
            bool             isNew  = false;
            StocksRepository stocks = null;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Welcome to the rates and stocks menu.\n\nWhat do you want to do?");
                Console.WriteLine("1. See more about rates.\n2. See more about stocks.\n3. Currency converter.\n4. Go back.");
                int.TryParse(Console.ReadLine(), out int choice);
                switch (choice)
                {
                case 1:
                {
                    Console.Clear();
                    rates.ShowAll();
                    Console.Read();
                    break;
                }

                case 2:
                {
                    Console.Clear();
                    if (!isNew)
                    {
                        stocks = new StocksRepository();
                        await stocks.CreateRepository();

                        isNew = true;
                    }
                    stocks.ShowAll();
                    Console.Read();
                    break;
                }

                case 3:
                {
                    CurrencyConverter.ConvertCurrency(rates);
                    break;
                }

                case 4:
                {
                    return;
                }

                default:
                {
                    Console.WriteLine("Wrong input. Please, try again.");
                    break;
                }
                }
            }
        }
Exemple #2
0
        public static void ConvertCurrency(RatesRepository rates)
        {
            Console.Clear();

            Rate rate1;
            Rate rate2;

            int    number = rates.Count + 1;
            int    rateNumber1;
            int    rateNumber2;
            double amount;

            Console.WriteLine("Please, choose 2 currencies.");
            for (int i = 0, j = rates.Count / 2; i < (rates.Count / 2) && j < rates.Count; i++, j++)
            {
                string str1 = $"{i + 1}. {rates[i].Cur_Name} ({rates[i].Cur_Abbreviation})";
                string str2 = $"{j+1}. {rates[j].Cur_Name} ({rates[j].Cur_Abbreviation})";
                Console.WriteLine($"{str1,-30} {str2}");
            }

            while (!int.TryParse(Console.ReadLine(), out rateNumber1) || rateNumber1 >= number || !rateNumber1.IsPositive())
            {
                Console.WriteLine("Wrong input. Please, try again.");
            }

            while (!int.TryParse(Console.ReadLine(), out rateNumber2) || rateNumber2 >= number || !rateNumber2.IsPositive())
            {
                Console.WriteLine("Wrong input. Please, try again.");
            }

            rate1 = rates.GetById(rateNumber1);
            rate2 = rates.GetById(rateNumber2);

            Console.WriteLine("Please, enter the amount of {0}", rate1.Cur_Name);

            while (!double.TryParse(Console.ReadLine(), out amount) || amount < 0)
            {
                Console.WriteLine("Wrong input. Please, try again.");
            }

            double converted = (rate1.Cur_OfficialRate / rate1.Cur_Scale) / (rate2.Cur_OfficialRate / rate2.Cur_Scale) * amount;

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write($"{amount} ");
            Console.ResetColor();
            Console.Write($"{rate1.Cur_Abbreviation} is ");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write($"{converted:F2} ");
            Console.ResetColor();
            Console.WriteLine($"{ rate2.Cur_Abbreviation}.");

            Console.ReadLine();
        }
Exemple #3
0
        public static async Task Main()
        {
            Logger.CreateLog();
            Logger.Log.Info("Application has started.");

            RatesRepository rates = new RatesRepository();
            await rates.CreateRepository();

            while (true)
            {
                DisplayMainMenu();
                int.TryParse(Console.ReadLine(), out int choice);
                switch (choice)
                {
                case 1:
                {
                    await RatesAndStocksMenu.MainMenuAsync(rates);

                    break;
                }

                case 2:
                {
                    SpendingManagementMenu.MainMenu();
                    break;
                }

                case 3:
                {
                    CreditsMenu.MainMenu();
                    break;
                }

                case 4:
                {
                    DepositsMenu.MainMenu();
                    break;
                }

                case 5:
                {
                    BudgetPlanningMenu.MainMenu();
                    break;
                }

                case 6:
                {
                    Logger.Log.Info("Application has stopped");
                    return;
                }
                }
            }
        }