Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight);
            users = new List <User>
            {
                new Admin("admin", "123", "Администратор"),
                new User("user", "123", "Пользователь"),
            };

            while (true)
            {
                Authentication.IsLogged = false;
                while (currentUser == null)
                {
                    currentUser = Authentication.Login();
                }
                Authentication.IsLogged = true;

                List <string> menuItems = new List <string>();
                if (currentUser.GetType() == typeof(User))
                {
                    menuItems.Add("Книги");
                    menuItems.Add("Мои книги");
                }
                else if (currentUser.GetType() == typeof(Admin))
                {
                    menuItems.Add("Книги");
                    menuItems.Add("Пользователи");
                }
                menuItems.Add("Выйти из аккаунта");
                menuItems.Add("Закрыть");

                Menu <string> menu = new Menu <string>(menuItems)
                {
                    Info            = "Здравствуйте, вы вошли как: " + currentUser.Name,
                    ItemInstruction = (item) =>
                    {
                        return(item);
                    },
                };
                menu.KeyInstructions = (key) =>
                {
                    if (key == ConsoleKey.UpArrow)
                    {
                        menu.SelectedItem--;
                    }
                    if (key == ConsoleKey.DownArrow)
                    {
                        menu.SelectedItem++;
                    }
                };
                if (currentUser.GetType() == typeof(User))
                {
                    menu.KeyInstructions += (key) =>
                    {
                        if (key == ConsoleKey.Enter)
                        {
                            if (menu.SelectedItem == 0)
                            {
                                Library.ShowBooks();
                            }
                            if (menu.SelectedItem == 1)
                            {
                                User.ShowBooks();
                            }
                            if (menu.SelectedItem == 2)
                            {
                                menu.IsClosed = true;
                                Authentication.Logout();
                            }
                            if (menu.SelectedItem == 3)
                            {
                                Environment.Exit(0);
                            }
                        }
                    }
                }
                ;
                else if (currentUser.GetType() == typeof(Admin))
                {
                    menu.KeyInstructions += (key) =>
                    {
                        if (key == ConsoleKey.Enter)
                        {
                            if (menu.SelectedItem == 0)
                            {
                                Library.ShowBooks();
                            }
                            if (menu.SelectedItem == 1)
                            {
                                Admin.ShowUsers();
                            }
                            if (menu.SelectedItem == 2)
                            {
                                menu.IsClosed = true;
                                Authentication.Logout();
                            }
                            if (menu.SelectedItem == 3)
                            {
                                Environment.Exit(0);
                            }
                        }
                    }
                }
                ;
                menu.Help += "Enter - выбор";
                while (Authentication.IsLogged)
                {
                    menu.Use();
                }
            }
        }