Example #1
0
        private static void adminMenu()
        {
            while (true)
            {
                Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n~~~~Admin Menu~~~~\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nPlease Choose from the below list" + "\n1) Admin Kills Running Game\n2) Admin adds a user\n3) Admin edits user\n4) Admin deletes user\n5) Admin unlocks locked user\n6) Return to User Menu\n7) Exit Program");
                var response = Console.ReadLine();
                switch (response)
                {
                case "1":     //Admin Kills Running Game
                    Console.WriteLine("Which game do you want to kill?");
                    var activeGames = ClsTest.getActiveGames();
                    foreach (DataRow aRow in activeGames.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["mapName"]);
                    }

                    var gameToKill    = Console.ReadLine();
                    var adminKillGame = ClsTest.adminKillGame(gameToKill);
                    foreach (DataRow aRow in adminKillGame.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["MESSAGE"]);
                    }
                    continue;

                case "2":     //Admin adds a user
                    Console.WriteLine("~~ Admin ~~ User registration\nPlease enter a Username");
                    var registerUserName = Console.ReadLine();
                    Console.WriteLine("Please enter a Email");
                    var registerEmail = Console.ReadLine();
                    Console.WriteLine("Please enter a Password");
                    var registerPassword = Console.ReadLine();
                    Console.WriteLine("Is this user an Admin?\n1)Yes\n2)No");
                    var    adminResponse = Console.ReadLine().ToString();
                    bool   registerAdmin;
                    string adminResponse = "1" ? registerAdmin = true : registerAdmin = false;
                    if (adminResponse = "1")
                    {
                        registerAdmin = true;
                    }
                    else
                    {
                        registerAdmin = false;
                    }

                    DataSet registerUser = ClsTest.adminAddUser(registerUserName, registerEmail, registerPassword, registerAdmin);
                    foreach (DataRow aRow in registerUser.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["Message"]);
                    }

                    continue;

                case "3":     //Admin edits user
                    Console.WriteLine("~~~~List of All Users~~~~");
                    DataSet allUsersEdit = ClsTest.adminGetAllUsers();
                    foreach (DataRow aRow in allUsersEdit.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["username"]);
                    }

                    Console.WriteLine("Please enter the name of the user you want to edit?");
                    string userToEdit = Console.ReadLine();
                    Console.WriteLine("Please enter the new username");
                    string newUserName = Console.ReadLine();
                    Console.WriteLine("Please enter the new password");
                    string newUserPassword = Console.ReadLine();
                    Console.WriteLine("Please enter the new email");
                    string newUserEmail = Console.ReadLine();
                    Console.WriteLine("Please enter the new login attempts amount");
                    int newLoginAttempts = Convert.ToInt16(Console.ReadLine());
                    Console.WriteLine("Please enter the new user score");
                    int newUserScore = Convert.ToInt16(Console.ReadLine());
                    Console.WriteLine("Is the user locked?\n1) Yes\n2) No");
                    string responseIsLocked = Console.ReadLine();
                    int    newIsLocked;
                    if (responseIsLocked == "1")
                    {
                        newIsLocked = 1;
                    }
                    else
                    {
                        newIsLocked = 0;
                    }

                    Console.WriteLine("Is this user an admin?\n 1) Yes\n2) No");
                    string responseIsAdmin = Console.ReadLine();
                    int    newIsAdmin;
                    if (responseIsAdmin == "1")
                    {
                        newIsAdmin = 1;
                    }
                    else
                    {
                        newIsAdmin = 0;
                    }

                    DataSet adminEditUser = ClsTest.adminEditUser(userToEdit, newUserName, newUserEmail, newUserPassword, newLoginAttempts, newUserScore, newIsLocked, newIsAdmin);
                    foreach (DataRow aRow in adminEditUser.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["MESSAGE"]);
                    }

                    continue;

                case "4":     //Admin deletes user
                    Console.WriteLine("~~~~List of All Users~~~~");
                    DataSet allUsers = ClsTest.adminGetAllUsers();
                    foreach (DataRow aRow in allUsers.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["username"]);
                    }

                    Console.WriteLine("Please enter the name of the user you want to delete?");
                    var     userToDelete = Console.ReadLine();
                    DataSet deleteUser   = ClsTest.adminDeleteUser(userToDelete);
                    foreach (DataRow aRow in deleteUser.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["Message"]);
                    }

                    continue;

                case "5":     //Admin unlocks locked user
                    Console.WriteLine("~~~~List of All Locked Users~~~~");
                    DataSet lockedUsers = ClsTest.adminGetLockedUsers();
                    foreach (DataRow aRow in lockedUsers.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["username"]);
                    }

                    Console.WriteLine("Please type the name of the user you want to unlock?");
                    var     userToUnlock = Console.ReadLine();
                    DataSet unlockUser   = ClsTest.adminUnlockUser(userToUnlock);
                    foreach (DataRow aRow in unlockUser.Tables[0].Rows)
                    {
                        Console.WriteLine(aRow["Message"]);
                    }

                    continue;

                case "6":
                    userMenu();
                    break;

                case "7":
                    Environment.Exit(0);
                    break;
                }

                break;
            }
        }