Пример #1
0
        public static void UpdateRemainingAmount(double sum)
        {
            CreditsRepository creditsRepository = new CreditsRepository();

            if (creditsRepository.Count == 0)
            {
                return;
            }

            int index;

            creditsRepository.ShowAll();

            Console.WriteLine("Please, enter credit ID.");

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

            creditsRepository._credits[index - 1].RemainingAmount -= sum;
            if (creditsRepository._credits[index - 1].RemainingAmount == 0)
            {
                creditsRepository._credits.RemoveAt(index - 1);
                foreach (var credit in creditsRepository._credits.Where(x => x.Id > index - 1))
                {
                    credit.Id--;
                }
            }
            creditsRepository.WriteToFile();

            Logger.Log.Info("Credit information was updated");
        }
Пример #2
0
        public static void MainMenu()
        {
            CreditsRepository creditsRepository = new CreditsRepository();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Welcome to Credits menu.\n\nWhat do you want to do?");
                Console.WriteLine("1. See all my credits.");
                Console.WriteLine("2. Add new credit.");
                Console.WriteLine("3. Delete credit.");
                Console.WriteLine("4. Go back.");

                int.TryParse(Console.ReadLine(), out int choice);
                switch (choice)
                {
                case 1:
                {
                    creditsRepository.ShowAll();
                    Console.ReadLine();
                    break;
                }

                case 2:
                {
                    creditsRepository.Add(Credit.Create(creditsRepository.Count + 1));
                    break;
                }

                case 3:
                {
                    creditsRepository.Delete();
                    break;
                }

                case 4:
                {
                    creditsRepository.WriteToFile();
                    return;
                }

                default:
                {
                    Console.WriteLine("Wrong input. Please, try again.");
                    break;
                }
                }
            }
        }