static void Pay(OrderInvoker invoker, Customer customer, Cashier cashier, Subject subject) { if (subject.OrderStatus == Constants.PayedStatus || subject.OrderStatus == Constants.CompletedStatus) { Console.WriteLine("You already paid."); } else { double sumToPay = invoker.GetOrder().TotalSum; if (customer.Budget >= sumToPay) { Console.Clear(); while (true) { Console.WriteLine($"You have to pay: {invoker.GetOrder().TotalSum}"); Console.WriteLine("Choose your payment method."); Console.WriteLine("1. Card"); Console.WriteLine("2. Paper Money"); Console.WriteLine("3. Coin Money"); int option; if (int.TryParse(Console.ReadLine(), out option)) { cashier.GetTotalCash(); switch (option) { case 1: cashier.CashIn(sumToPay, EMoneyType.Card); break; case 2: cashier.CashIn(sumToPay, EMoneyType.Paper); break; case 3: cashier.CashIn(sumToPay, EMoneyType.Coin); break; default: Console.WriteLine("Invalid option"); return; } Console.WriteLine("Cash in..."); customer.Budget -= sumToPay; cashier.GetTotalCash(); subject.OrderStatus = Constants.PayedStatus; break; } else { Console.WriteLine("Invalid option!"); } } } else { Console.WriteLine("Not enough money."); } } }
static void Main(string[] args) { List <Customer> customers = DriverManager.GetInstance().GenerateCustomers(); Cashier cashier = DriverManager.GetInstance().GenerateCashier(); Menu menu = new Menu("Menu", "Daily Menu"); menu.MenuItems = DriverManager.GetInstance().GenerateMenuItems(); Subject subject; Observer observer; Customer currentCustomer = null; OrderInvoker invoker = null; Console.WriteLine("Choose customer: "); for (int i = 0; i < customers.Count; i++) { Console.WriteLine($"{i} {customers[i]}"); } while (true) { int customerOption; if (int.TryParse(Console.ReadLine(), out customerOption)) { if (customerOption <= customers.Count) { currentCustomer = customers[customerOption]; invoker = new OrderInvoker(currentCustomer); subject = new Subject(invoker.GetOrder()); observer = new Observer(currentCustomer); subject.Register(observer); break; } Console.WriteLine("Please choose a valid customer!"); } else { Console.WriteLine("Invalid option"); } } while (true) { Console.WriteLine("===== Menu ====="); Console.WriteLine("0. Exit"); Console.WriteLine("1. Show Menu"); Console.WriteLine("2. Order"); Console.WriteLine("3. Pay"); Console.WriteLine("4. Checkout"); Console.WriteLine("5. Display order"); Console.WriteLine("Enter option: "); int option; if (int.TryParse(Console.ReadLine(), out option)) { Console.Clear(); switch (option) { case 1: IIterator iterator = menu.CreateMenuIterator(); menu.PrintMenu(iterator); break; case 2: ChooseOrderMenu(invoker, menu); subject.OrderStatus = Constants.InProgressStatus; break; case 3: Pay(invoker, currentCustomer, cashier, subject); break; case 4: if (subject.OrderStatus == Constants.PayedStatus) { Order customerOrder = invoker.GetOrder(); Ticket ticket = new Ticket(customerOrder.TotalSum, customerOrder.MenuItems); Ticket customerTicket = ticket.Clone(); Ticket restaurantTicket = ticket.Clone(); Console.WriteLine($"Customer ticket: {customerTicket}"); Console.WriteLine($"Restaurant ticket: {restaurantTicket}"); invoker.DeleteOrder(); subject.OrderStatus = Constants.CompletedStatus; } else { Console.WriteLine("You cannot checkout before you pay."); } break; case 5: Order order = invoker.GetOrder(); Console.WriteLine(order); break; case 0: return; default: break; } } else { Console.WriteLine("Invalid option"); } } }