Example #1
0
        public string UserRoles(List <string> userMenu, string username, string password, int accessLevel)
        {
            AccessLevelCheck alc = new AccessLevelCheck(username, password, accessLevel);

            DATABASE_CS.DBPrintUsers pu = new DATABASE_CS.DBPrintUsers();

            SqlConnection con = new SqlConnection(pu.ConncetionString);
            List <string> listOfUsersString = pu.DBUsersPrintString(username);
            AllMenus      am = new AllMenus(username, password, accessLevel);

            while (true)
            {
                for (int i = 0; i < listOfUsersString.Count; i++)
                {
                    Console.Clear();
                    Console.WriteLine("  MESSAGES CLIENT");
                    Console.WriteLine($"   Welcome <{username.ToUpper()}>!");
                    Console.WriteLine($"     Level: {accessLevel}");
                    Console.WriteLine();
                    Console.CursorVisible = true;
                    Console.WriteLine("Please Select User! Press any key to select..");
                    Console.ReadKey();
                    Console.CursorVisible = false;

                    string roleUsername = (Menu.MenuRun(listOfUsersString, username, accessLevel)).Trim();
                    #region Main Menus
                    if (roleUsername == "Main Menu")
                    {
                        Console.Clear();
                        alc.LevelMenuCall(username, password);
                    }
                    #endregion

                    #region List Menus
                    else
                    {
                        Console.Clear();
                        Console.Clear();
                        Console.WriteLine("  MESSAGES CLIENT");
                        Console.WriteLine($"   Welcome <{username.ToUpper()}>!");
                        Console.WriteLine($"     Level: {accessLevel}");
                        Console.WriteLine();
                        string currentRole = alc.CheckAccessLevelByUsername(roleUsername);
                        Console.CursorVisible = true;
                        Console.WriteLine($"You selected (({roleUsername.Trim()})) whose role is ({currentRole}). \nPlease Select his Role! \nPress any key to select..");
                        Console.ReadKey();
                        Console.Clear();
                        Console.CursorVisible = false;
                        List <string> RoleList = new List <string> {
                            "User", "Admin", "Super Admin", "Back"
                        };
                        var AccessLevel = Menu.MenuRun(RoleList, username, accessLevel);
                        if (AccessLevel == "Super Admin")
                        {
                            DBRole(roleUsername, 3);
                        }
                        else if (AccessLevel == "Admin")
                        {
                            DBRole(roleUsername, 2);
                        }
                        else if (AccessLevel == "Back")
                        {
                            Console.Clear();
                            alc.LevelMenuCall(username, password);
                        }
                        else
                        {
                            DBRole(roleUsername, 1);
                        }
                        Console.Clear();
                        Console.WriteLine("  MESSAGES CLIENT");
                        Console.WriteLine($"   Welcome <{username.ToUpper()}>!");
                        Console.WriteLine($"     Level: {accessLevel}");
                        Console.WriteLine();
                        Console.WriteLine($"The new AccessLevel of User {roleUsername} is {AccessLevel}.");
                        Console.ReadKey();
                        Console.Clear();
                        alc.LevelMenuCall(username, password);
                    }
                    #endregion
                }
            }
        }
Example #2
0
        public void ActionsUsers(List <string> superMenu, string username, string password, int accessLevel)
        {
            DBManipulateUser du = new DBManipulateUser();

            DATABASE_CS.DBPrintUsers pu = new DATABASE_CS.DBPrintUsers();
            List <string>            listOfUsersString = pu.DBUsersPrintString(username);
            string changeUsername = (Menu.MenuRun(listOfUsersString, username, accessLevel)).Trim();

            Console.Clear();
            string SuperMenuItem = (Menu.MenuRun(superMenu, username, accessLevel)).Trim();
            string newUsername   = "";
            string newPassword   = "";

            if (SuperMenuItem == "Delete User")
            {
                string actionString = "delete from dbo.Users where Username = @Username; delete from dbo.Messages where Sender = @Username or Receiver = @Username;";
                du.DBUserManipulate(changeUsername, "delete", actionString, username, password, newUsername, newPassword);
            }

            else if (SuperMenuItem == "Change User's Password")
            {
                Console.Clear();
                Console.WriteLine("Change User's Password");
                Console.WriteLine();
                Console.CursorVisible = true;
                Console.WriteLine($"Please Enter new Password for user {changeUsername}: ");
                newPassword           = Console.ReadLine().Trim();
                Console.CursorVisible = false;
                string actionString = "Update dbo.Users set Password = @Password where Username = @Username";
                du.DBUserManipulate(changeUsername, "change Password", actionString, username, password, newUsername, newPassword);
            }
            else if (SuperMenuItem == "Change User Role")
            {
                Console.Clear();
                Console.WriteLine("USER ROLES");
                Console.WriteLine("");
                DBPrintUsers pu2 = new DBPrintUsers();
                AssignRoles  ar  = new AssignRoles();
                SuperMenuItem = pu2.DBUsersPrintString(username).ToString();
                ar.UserRoles(listOfUsersString, username, password, accessLevel);
                Console.Clear();
            }
            else if (SuperMenuItem == "Change User's Username")
            {
                Console.Clear();
                Console.WriteLine("Change User's Username");
                Console.WriteLine();
                Console.CursorVisible = true;
                Console.WriteLine($"Please Enter new Username for user {changeUsername}: ");
                newUsername           = Console.ReadLine().Trim();
                Console.CursorVisible = false;
                bool        Verify = false;
                DBCheckUser dbc    = new DBCheckUser();
                Verify = dbc.DBUserCheck(newUsername);
                int i = 0;
                while ((Verify == true || newUsername.Length < 1) && i < 2)
                {
                    i++;
                    Console.Clear();
                    Console.WriteLine("LOGIN");
                    Console.WriteLine();
                    Console.WriteLine($"Username <<{newUsername}>> Exist. Try another one ({3 - i} more tries):");
                    Console.CursorVisible = true;
                    Console.Write("Username: "******"End of Tries!! \n Press any key to continue...");
                        Console.ReadKey();
                        Console.CursorVisible = false;
                        alc.LevelMenuCall(username, password);
                    }
                }
                string actionString = "Update dbo.Users set Username = @NewUsername where Username = @Username; Update dbo.Messages set Sender = @NewUsername where Sender = @Username; Update dbo.Messages set Receiver = @NewUsername where Receiver = @Username;";
                du.DBUserManipulate(changeUsername, "change Username", actionString, username, password, newUsername, newPassword);
            }
        }