Пример #1
0
        static void Main(string[] args)
        {
            Context      context = new Context();
            StateFactory factory = StateFactory.GetInstance;
            ServiceDB    db      = ServiceDB.GetInstance;

            context.ChangeState(factory.GetState("customer"));

            Console.WriteLine(context.Run(""));
        }
        public override string Execute(string[] command, State state)
        {
            ServiceDB db = ServiceDB.GetInstance;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine();

            sb.AppendLine(db.ToString());

            return(sb.ToString());
        }
        public override string Execute(string[] command, State aState)
        {
            StringBuilder  sb      = new StringBuilder();
            Table          t       = aState.Context.Table;
            ServicePayment payment = ServicePayment.GetInstance;
            ServiceDB      db      = ServiceDB.GetInstance;

            Console.WriteLine();
            Console.WriteLine($"Table {t.Id} Order comes to {t.Order.TotalCost()}.");
            Console.Write("Confirm (y/n):> ");
            string confirm = Console.ReadLine();

            if (confirm.ToLower() == "y")
            {
                Console.WriteLine("Paying Invoice...");

                // Call Payment Service...
                bool response = payment.ProcessPayment(t.Order);
                if (response)
                {
                    sb.AppendLine("Order has been paid for in full");

                    // Call DB Stats Service...
                    db.AddStatistics(t.Order);

                    // Reset Table.
                    t.Order       = new Order(t);
                    t.Reservation = null;
                }
                else
                {
                    sb.AppendLine("Payment has failed, please try again.");
                }
            }
            else
            {
                sb.AppendLine("Order has not been paid for.");
            }

            return(sb.ToString());
        }