Exemple #1
0
        /// <summary>
        /// Gets and validates the menu input from the user.
        /// </summary>
        /// <returns>Returns a tuple. menuInput is the string input from user,
        /// and validatedInput is the tryparsed menuchoice</returns>
        public static (string menuInput, int validatedInput) GetAndValidateInput()
        {
            var menuInput      = InputHelper.AskForMenuInput();
            var validatedInput = InputHelper.ValidateMenuInput(menuInput);

            return(menuInput, validatedInput);
        }
        /// <summary>
        /// Prints Admin menu
        /// </summary>
        /// <param name="admin">Takes a user with admin priviliges</param>
        public static void PrintAdminSelectionMenu(User admin)
        {
            SharedView.PrintWithGreenText($"\tVälkommen {admin.Name}");
            var logoutUser = false;

            do
            {
                GeneralViewHelper.WaitAndClearScreen();
                AdminView.Print();
                string menuInput      = InputHelper.AskForMenuInput();
                int    validatedInput = InputHelper.ValidateMenuInput(menuInput);
                logoutUser = SharedController.LogoutIf_X_IsPressed(admin, menuInput, validatedInput);
                if (logoutUser)
                {
                    continue;
                }
                else
                {
                    switch (validatedInput)
                    {
                    case 1:
                        AdminFunctions(admin);
                        break;

                    case 2:
                        SharedController.BuyBookMenu(admin);
                        break;
                    }
                }
            } while (!logoutUser);
        }
Exemple #3
0
        /// <summary>
        /// Method for printing the main menu
        /// </summary>
        public static void PrintMainMenu()
        {
            int    userMenuChoice;
            string menuInput = default;

            do
            {
                Console.Clear();
                StartView.Print();
                menuInput      = InputHelper.AskForMenuInput();
                userMenuChoice = InputHelper.ValidateMenuInput(menuInput);

                if (userMenuChoice == 0 && menuInput.ToLower() != "q")
                {
                    SharedError.PrintWrongMenuInput();
                }
                else
                {
                    var api = new WebShopApi();
                    switch (userMenuChoice)
                    {
                    case 1:
                        var userCredentials = LoginView.PrintLoginPage();
                        var user            = api.Login(userCredentials.userName, userCredentials.password);

                        if (UserController.UserIsNull(user) &&
                            !userCredentials.userName.Contains(abortChar))
                        {
                            SharedError.PrintWrongCredentials(user);

                            continue;
                        }
                        else if (userCredentials.userName.Contains(abortChar))
                        {
                            break;
                        }
                        else if (user.IsAdmin)
                        {
                            AdminController.PrintAdminSelectionMenu(user);
                        }
                        else
                        {
                            UserController.UserSelectionMenu(user);
                        }
                        break;

                    case 2:
                        var registererUserCredentials = UserView.Register();
                        if (!api.Register(registererUserCredentials.username,
                                          registererUserCredentials.password,
                                          registererUserCredentials.verifyPassword))
                        {
                            SharedError.Failed();
                            break;
                        }
                        SharedError.Success();
                        break;

                    case 0:
                        Environment.Exit(1);
                        break;

                    default:
                        SharedError.PrintWrongMenuInput();
                        break;
                    }
                }
            } while (menuInput.ToLower() != "q");
        }