예제 #1
0
        public void ShowRecipe(IListable recipe)
        {
            var onRecipe = _storage.Recipes.GetAll().First(c => c.Id == recipe.Id);

            _topView.ShowMenu(onRecipe.Name);

            Console.SetCursorPosition(5, 5);

            Console.WriteLine("Ингредиенты:\n");

            foreach (var ingredientId in onRecipe.IngredientsId)
            {
                var ingredient = _storage.Ingredients.GetAll().First(c => c.Id == ingredientId.Key);

                Console.WriteLine($"{ingredient.Name}  = {ingredientId.Value} { GetDescription(ingredient.Measure)}");
            }

            Console.WriteLine("\n     Описание\n");
            Console.WriteLine(onRecipe.Explanation + "\n\n");

            Console.WriteLine("     Шаги приготовления:\n");

            foreach (var step in onRecipe.Steps)
            {
                Console.WriteLine(step);
            }


            ConsoleKey key;

            Console.WriteLine("\n\nНажмите Esc для выхода >");
            do
            {
                key = Console.ReadKey().Key;
            } while (key != ConsoleKey.Escape);
        }
예제 #2
0
        public void Create()
        {
            _topView.ShowMenu("Новый ингридиент. Enter - создать, Esc - отмена >");

            Console.SetCursorPosition(1, 5);
            Console.Write("Enter - создать, Esc - отмена >");

            ConsoleKey key;

            do
            {
                Console.SetCursorPosition(0, 5);
                key = Console.ReadKey().Key;

                if (key == ConsoleKey.Escape)
                {
                    _topView.ShowMenu();

                    return;
                }
            } while (key != ConsoleKey.Enter);

            Console.SetCursorPosition(1, 7);

            Ingredient newIngredient = new Ingredient();

            Console.Write("Введите название:");
            newIngredient.Name = Console.ReadLine();

            Console.SetCursorPosition(1, 9);
            Console.Write("Выберите единицу измерения:\n");

            var measures = Enum.GetValues(typeof(Measurements));

            foreach (Measurements VARIABLE in measures)
            {
                Console.WriteLine($"{(int) VARIABLE} - {GetDescription(VARIABLE)}");
            }

            Measurements result;

            do
            {
                Enum.TryParse(Console.ReadLine(), out result);
            } while (!Enum.IsDefined(typeof(Measurements), result));

            newIngredient.Measure = result;

            var lastId = _storage.GetAll().Max(c => c.Id);

            ;
            newIngredient.Id = ++lastId;

            Console.Write("\nСохранить ингредиент? Д/Н : ");
            string answer = Console.ReadLine()?.ToUpper();

            if (answer != null && answer.Equals("Д"))
            {
                _storage.Create(newIngredient);

                try
                {
                    _fileSaver.SaveFiles();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);

                    throw;
                }

                Console.WriteLine("Ингредиент сохранен!");
                Thread.Sleep(2000);
            }

            _topView.ShowMenu();
        }