Ejemplo n.º 1
0
        /// <summary>
        /// Shows the specific dish menu in order.
        /// </summary>
        /// <param name="currentOrder">Order.</param>
        private void EditSpecificDishMenuIn(ref BusinessLogic.Order currentOrder)
        {
            bool done = false;

            Console.Write ("Виберіть номер страви для редагування: ");
            try {
                var userOption = int.Parse (Console.ReadLine ()) - 1;
                while (!done) {
                    if (userOption >= 0 && userOption < currentOrder.Dishes.Count) {
                        Console.WriteLine (currentOrder.Dishes.ElementAt (userOption));
                        Console.WriteLine ("1. Додати інгрідієнтів");
                        Console.WriteLine ("2. Видалити інгрідієнти");
                        Console.WriteLine ("3. Змінити інгредієнт");
                        Console.WriteLine ("4. Змінити назву страви");
                        Console.WriteLine ("5. Змінити ціну на страву");
                        Console.WriteLine ("6. Змінити час приготування страви");
                        Console.WriteLine ("7. Повернутися");
                        CommandPromtWithColor (ConsoleColor.Cyan);

                        switch (int.Parse (Console.ReadLine ())) {
                        case 1:
                            Console.WriteLine ("Існуючі інгредієнти: ");
                            DisplayPredefinedIngredients ();
                            do {
                                Console.Write ("Виберіть інгредінти для додавання (розділяйте через один пустий символ) або створіть свій (+): ");
                                var ingredientsInput = Console.ReadLine ().Split (' ');
                                try {
                                    IEnumerable<int> parsedIngedientsInput;
                                    if (ingredientsInput [0].Equals ("+")) {
                                        currentOrder.Dishes.ElementAt (userOption).AddIngredient (CreateIngredientUsing (predefinedIngredients));
                                    } else {
                                        parsedIngedientsInput = ingredientsInput.Select (x => int.Parse (x) - 1);
                                        foreach (var i in parsedIngedientsInput) {
                                            currentOrder.Dishes.ElementAt (userOption).AddIngredient (predefinedIngredients.ElementAt (i));
                                        }
                                    }
                                } catch (Exception) {
                                    Console.WriteLine ("Помилка при додаванні інгредієнтів.");
                                    continue;
                                }
                                break;
                            } while(true);
                            break;
                        case 2:
                            do {
                                Console.Write ("Виберіть номера інгредієнтів для видалення (розділяйте через один пустий символ): ");
                                var ingredientsToRemove = Console.ReadLine ().Split (' ');
                                try {
                                    IEnumerable<int> parsedIngredientsToRemove = ingredientsToRemove.Select (x => int.Parse (x) - 1);
                                    foreach (var i in parsedIngredientsToRemove) {
                                        currentOrder.Dishes.ElementAt (userOption).RemoveIngredientById (i);
                                    }
                                } catch (Exception) {
                                    Console.WriteLine ("Помилка при введенні номерів інгредієнтів для видалення.");
                                    continue;
                                }
                                Console.WriteLine ("Видалення успішне.");
                                break;
                            } while (true);
                            break;

                        case 3:
                            Console.WriteLine (currentOrder.Dishes.ElementAt (userOption).PrintIngredients ());
                            Console.Write ("Номер інгредієнта для зміни: ");

                            try {
                                var ingredientToChange = currentOrder.Dishes.ElementAt (userOption).Ingredients.ElementAt (int.Parse (Console.ReadLine ()) - 1);

                                predefinedIngredients.Remove (ingredientToChange);
                                currentOrder.Dishes.ElementAt (userOption).RemoveIngredient (ingredientToChange);

                                Console.Write ("Нове ім'я: ");
                                var newIngredientName = Console.ReadLine ();
                                Console.Write ("Нова ціна: ");
                                var newIngredientPrice = double.Parse (Console.ReadLine ());

                                var newIngredient = new BusinessLogic.Ingredient (newIngredientName, newIngredientPrice);

                                predefinedIngredients.Add (newIngredient);
                                currentOrder.Dishes.ElementAt (userOption).AddIngredient (newIngredient);

                                Console.WriteLine ("Інгредієнт успішно змінено!");
                            } catch (FormatException) {
                                Console.WriteLine ("Невірний номер інгредієнта. Спробуйте ще раз!");
                            } catch (Exception) {
                                Console.WriteLine ("Помилка при зміні інгрідієнта.");
                                continue;
                            }
                            break;
                        case 4:
                            Console.Write ("Бажане ім'я для страви: ");
                            currentOrder.SetDishName (currentOrder.Dishes.ElementAt (userOption), Console.ReadLine ());
                            break;
                        case 5:
                            do {
                                Console.Write ("Ціна на страву: ");
                                try {
                                    var dishPrice = double.Parse (Console.ReadLine ());
                                    currentOrder.SetDishPrice (currentOrder.Dishes.ElementAt (userOption), dishPrice);
                                } catch (Exception) {
                                    continue;
                                }
                                break;
                            } while(true);
                            break;
                        case 6:
                            Console.Write ("Час приготування: ");
                            var dishTime = double.Parse (Console.ReadLine ());
                            currentOrder.SetDishCookTime (currentOrder.Dishes.ElementAt (userOption), dishTime);
                            Console.WriteLine ("Успішне змінений час приготування!\n");
                            break;
                        case 7:
                            done = true;
                            break;
                        default:
                            throw new ArgumentOutOfRangeException ("Немає такої опції.");
                        }
                        currentOrder.UpdateTotalCost();
                    } else {
                        throw new ArgumentOutOfRangeException ("Немає такої опції.");
                    }
                }
            } catch (FormatException) {
                Console.WriteLine ("На вході отримано не число.");
            } catch (ArgumentOutOfRangeException) {
                Console.WriteLine ("Вихід за межі діапазону.");
            } catch (ArgumentNullException) {
                Console.WriteLine ("Отримано пустий параметр.");
            }
        }