Ejemplo n.º 1
0
        /// <summary>
        /// Shows the edit dishes menu with selected order.
        /// </summary>
        /// <param name="order">Order.</param>
        private void EditOrderDishesMenu(BusinessLogic.Order order)
        {
            bool done = false;
            while (!done) {
                Console.WriteLine ("Страви в замовленні:\n");
                Console.WriteLine (order.PrintDishes ());

                Console.WriteLine ("1. Додати страву");
                Console.WriteLine ("2. Редагувати страву");
                Console.WriteLine ("3. Видалити страву");
                Console.WriteLine ("4. Повернутися");
                CommandPromtWithColor (ConsoleColor.Cyan);
                try {
                    var userOption = int.Parse (Console.ReadLine ());

                    switch (userOption) {
                    case 1:
                        AddDishesTo (order);
                        break;
                    case 2:
                        EditSpecificDishMenuIn (ref order);
                        break;
                    case 3:
                        do {
                            Console.Write ("Виберіть страви (розділяйте одним пустим символом): ");
                            try {
                                var dishesToRemove = Console.ReadLine ().Split (' ');
                                IEnumerable<int> parsedDishesToRemove = dishesToRemove.Select (x => int.Parse (x) - 1);
                                foreach (var i in parsedDishesToRemove) {
                                    order.RemoveDishById (i);
                                }
                                Console.WriteLine ("Видалення успішне.");
                            } catch (Exception) {
                                Console.WriteLine ("Проблема при видаленні страв(и)");
                                continue;
                            }
                            break;
                        } while(true);
                        break;
                    case 4:
                        done = true;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException ("Немає такої опції.");
                    }
                } catch (FormatException) {
                    Console.WriteLine ("На вході отримано не число.");
                } catch (ArgumentOutOfRangeException e) {
                    Console.WriteLine (e.ParamName);
                }
            }
        }