Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.Unicode;
            Console.InputEncoding  = Encoding.Unicode;
            var d = new UnitOfWork();

            var nc = new NavigationController(d);
            var cc = new CategoryController(d);
            var rc = new RecipeController(d);

            nc.ReloadData();
            PrintTree(nc);

            while (true)
            {
                try
                {
                    var key = Console.ReadKey();

                    switch (key.Key)
                    {
                    case ConsoleKey.DownArrow:
                        if (nc.Next())
                        {
                            PrintTree(nc);
                        }
                        break;

                    case ConsoleKey.UpArrow:
                        if (nc.Prev())
                        {
                            PrintTree(nc);
                        }
                        break;

                    case ConsoleKey.Enter:
                        if (nc.Current is Recipe)
                        {
                            PrintRecipe(nc.Current as Recipe);
                            Console.ReadLine();
                            PrintTree(nc);
                        }
                        else
                        if (nc.Current is Category)
                        {
                            nc.Enter();
                            PrintTree(nc);
                        }
                        break;

                    case ConsoleKey.Backspace:
                        nc.Exit();
                        PrintTree(nc);
                        break;

                    case ConsoleKey.Q:
                        return;

                    case ConsoleKey.N:
                        Console.Clear();
                        OutputLine("Creating a new recipe", ConsoleColor.Blue);
                        var recipe = EnterRecipe(nc.Root?.Id);
                        recipe = rc.CreateRecipe(recipe);
                        while (true)
                        {
                            var res = EnterIngredient();
                            rc.AddIngredient(recipe, res.Ingredient, res.Amount);
                            OutputLine("Enter to continue adding, Backspace to exit", ConsoleColor.Cyan);
                            if (Console.ReadKey().Key != ConsoleKey.Enter)
                            {
                                break;
                            }
                        }
                        while (true)
                        {
                            var res = EnterStep();
                            rc.AddDirection(recipe, res);
                            OutputLine("Enter to continue adding, Backspace to exit", ConsoleColor.Cyan);
                            if (Console.ReadKey().Key != ConsoleKey.Enter)
                            {
                                break;
                            }
                        }
                        nc.ReloadData(nc.Root?.Id);
                        PrintTree(nc);
                        break;

                    case ConsoleKey.C:
                        Console.Clear();
                        OutputLine("Creating a new category", ConsoleColor.Blue);
                        var category = EnterCategory(nc.Root?.Id);
                        category = cc.CreateCategory(category);
                        nc.ReloadData(nc.Root?.Id);
                        PrintTree(nc);
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    OutputLine($"ERROR: { ex.Message }", ConsoleColor.Red);
                }
            }
        }