Esempio n. 1
0
        /// <summary>
        /// Creates the ingredient from collection.
        /// </summary>
        /// <returns>Ingredient.</returns>
        /// <param name="predefinedIngredients">Ingredient collection.</param>
        private BusinessLogic.Ingredient CreateIngredientUsing(List <BusinessLogic.Ingredient> predefinedIngredients)
        {
            Console.Write("Введіть назву інгрідієнта: ");
            string ingredientName  = Console.ReadLine();
            double ingredientPrice = 0;

            try {
                if (!(new Regex(@"[A-Za-z\p{IsCyrillic}]+").IsMatch(ingredientName)))
                {
                    throw new FormatException();
                }
                Console.Write("Введіть ціну інгрідієнта: ");
                ingredientPrice = double.Parse(Console.ReadLine());
            } catch (FormatException) {
                Console.WriteLine("Назва інгредієнта містить недопустимі символи.");
            }

            var newIngredient = new BusinessLogic.Ingredient(ingredientName, ingredientPrice);

            predefinedIngredients.Add(newIngredient);
            return(newIngredient);
        }
Esempio n. 2
0
 public void RemoveIngredient(Ingredient ingredient)
 {
     Price -= ingredient.Price;
     Ingredients.Remove (ingredient);
 }
Esempio n. 3
0
 public void AddIngredient(Ingredient ingredient)
 {
     Ingredients.Add (ingredient);
     Price += ingredient.Price;
 }
 public void Initialize()
 {
     dish = new BusinessLogic.Dish ();
     ingredient1 = new BusinessLogic.Ingredient ("sample1", 10);
     ingredient2 = new BusinessLogic.Ingredient ("sample2", 15);
 }
Esempio n. 5
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("Отримано пустий параметр.");
            }
        }
Esempio n. 6
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 ("Отримано пустий параметр.");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the ingredient from collection.
        /// </summary>
        /// <returns>Ingredient.</returns>
        /// <param name="predefinedIngredients">Ingredient collection.</param>
        private BusinessLogic.Ingredient CreateIngredientUsing(List<BusinessLogic.Ingredient> predefinedIngredients)
        {
            Console.Write ("Введіть назву інгрідієнта: ");
            string ingredientName = Console.ReadLine ();
            double ingredientPrice = 0;

            try {
                if (!(new Regex (@"[A-Za-z\p{IsCyrillic}]+").IsMatch (ingredientName))) {
                    throw new FormatException ();
                }
                Console.Write ("Введіть ціну інгрідієнта: ");
                ingredientPrice = double.Parse (Console.ReadLine ());
            } catch (FormatException) {
                Console.WriteLine ("Назва інгредієнта містить недопустимі символи.");
            }

            var newIngredient = new BusinessLogic.Ingredient (ingredientName, ingredientPrice);

            predefinedIngredients.Add (newIngredient);
            return newIngredient;
        }
 public void Initialize()
 {
     dish        = new BusinessLogic.Dish();
     ingredient1 = new BusinessLogic.Ingredient("sample1", 10);
     ingredient2 = new BusinessLogic.Ingredient("sample2", 15);
 }