public void MakeCoffee(int index) { Coffee cof = unitOfWork.Coffee.Get(index - 1); var ing = unitOfWork.Ingredients.GetAll().First(); if (Purse.Balance >= cof.Price && ing.Coffe >= cof.Coffe && ing.Sugar >= cof.Sugar && ing.Water >= cof.Sugar) { Purse.Remove(cof.Price); ing.Coffe -= cof.Coffe; ing.Sugar -= cof.Sugar; ing.Water -= cof.Water; Console.WriteLine($"\nProduct is ready"); Console.WriteLine($"Your balance - {Purse.Balance}"); Console.WriteLine("Choose another coffee or add money or you can end by pressing 0ю"); unitOfWork.SaveChanges(); } else if (Purse.Balance < cof.Price) { Console.WriteLine("\nNot enought money."); ShowAllCoffies(); } else { Console.WriteLine("\nWe are sorry but we do not have enough ingredients."); ShowAllCoffies(); } }
static void Main(string[] args) { Console.WriteLine("Welcome\n\n"); CoffeeMachine machine = new CoffeeMachine(); int input = -1; do { if (!int.TryParse(Console.ReadLine(), out input)) { Console.WriteLine("\nPlease enter money or coffee index.\n"); input = -1; } if (input > 0 && input <= 10) { machine.MakeCoffee(input); } else if (input > 10) { Purse.Add(input); Console.WriteLine($"\nYour balance {Purse.Balance}\n"); } else if (input == 0) { Console.WriteLine("\nThank you."); Console.WriteLine($"Get back - {Purse.Balance}"); Purse.Remove(Purse.Balance); Thread.Sleep(1500); } } while (input != 0); }