Exemple #1
0
        public static void MainMenu()
        {
            SpendingsRepository spendingsRepository = new SpendingsRepository();

            while (true)
            {
                Console.Clear();
                Hints.GetRandomHint();
                Console.WriteLine("\n\n");
                Console.WriteLine("Welcome to Spending Management menu.\n\nWhat do You want to do?");
                Console.WriteLine("1. Add new spending.");
                Console.WriteLine("2. See all spendings in last 30 days.");
                Console.WriteLine("3. See spendings of specified category.");
                Console.WriteLine("4. Clear history.");
                Console.WriteLine("5. Go back.");
                int.TryParse(Console.ReadLine(), out int choice);
                switch (choice)
                {
                case 1:
                {
                    Console.Clear();
                    Spending tmp = Spending.Create();
                    spendingsRepository.Add(tmp);
                    break;
                }

                case 2:
                {
                    ShowSpendings(spendingsRepository);
                    break;
                }

                case 3:
                {
                    SpecifiedSpendings(spendingsRepository);
                    break;
                }

                case 4:
                {
                    spendingsRepository.ClearHistory();
                    break;
                }

                case 5:
                {
                    spendingsRepository.WriteToFile();
                    return;
                }

                default:
                    Console.WriteLine("Wrong input. Please, try again.");
                    break;
                }
            }
        }
Exemple #2
0
 private static void SpecifiedSpendings(SpendingsRepository spendingsRepository)
 {
     while (true)
     {
         Console.Clear();
         Console.WriteLine("To exit enter 0.");
         var category = Spending.ChooseCategory();
         if (category == 0)
         {
             return;
         }
         spendingsRepository.ShowByCategory((SpendingCategory)category);
         Console.ReadLine();
     }
 }
Exemple #3
0
        public static void SpendingAdded(Spending spending)
        {
            Logger.Log.Info("Budget information was updated");

            var budgetPlan = new BudgetPlan();

            if (DateTimeOffset.Now > budgetPlan.ExpirationDate)
            {
                return;
            }
            var spend = budgetPlan.Spendings.Where(x => x.Category == spending.Category).ToList();

            spend[0].SpentAmount += spending.MoneyAmount;

            budgetPlan.Dispose();
        }
Exemple #4
0
        public static Spending Create()
        {
            Spending spending = new Spending();
            double   money;

            Console.WriteLine("Enter an amount of money.");
            while (!double.TryParse(Console.ReadLine(), out money) || !money.IsPositive())
            {
                Console.WriteLine("Wrong input. Please, try again.");
            }

            SpendingCategory category = (SpendingCategory)Spending.ChooseCategory();

            spending.Category    = category;
            spending.MoneyAmount = money;
            spending.Date        = DateTimeOffset.UtcNow;

            Logger.Log.Info("New spending was created");
            return(spending);
        }