public bool DBUserManipulate(string deleteUsername, string action, string actionString, string username, string password, string newUsername, string newPassword) { bool isUserDeleted = false; SqlConnection con = new SqlConnection(ConnectionString); //string actionString = "Select User delete from dbo.Users where Username = @Username"; SqlCommand cmd = new SqlCommand("Select * from dbo.Users where Username = @Username", con); cmd.Parameters.AddWithValue("@Username", deleteUsername); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (dr.HasRows == true) { Console.WriteLine($"User {deleteUsername} Exists. \nShould I {action}??"); Console.CursorVisible = true; Console.Write("Press any key to Continue. =>To Abort press ESC<= ..."); var key2 = Console.ReadKey(); Console.CursorVisible = false; if (key2.Key == ConsoleKey.Escape) { AccessLevelCheck alc = new AccessLevelCheck(); Console.Clear(); alc.LevelMenuCall(username, password); } else { dr.Close(); SqlCommand cmdAction = new SqlCommand(actionString, con); cmdAction.Parameters.AddWithValue("@Username", deleteUsername); cmdAction.Parameters.AddWithValue("@NewUsername", newUsername); cmdAction.Parameters.AddWithValue("@Password", newPassword); try { Console.Clear(); SqlDataReader drDelete = cmdAction.ExecuteReader(); isUserDeleted = true; Console.WriteLine($"User {deleteUsername}, {action} successfully!"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine(e.Message + $"User {deleteUsername}, {action} NOT successfully!"); Console.ReadLine(); } break; } } else { isUserDeleted = false; } } return(isUserDeleted); }
public bool MessageManipulate(string username, string password, string action, string actionString, string newMessage, int messageID) { bool isUserDeleted = false; SqlConnection con = new SqlConnection(ConnectionString); Console.Clear(); Console.WriteLine($"Message {action}: {newMessage}. \nShould I proceed??"); Console.CursorVisible = true; Console.Write("Press any key to Continue. =>To Abort press ESC<= ..."); Console.Clear(); var key2 = Console.ReadKey(); Console.CursorVisible = false; if (key2.Key == ConsoleKey.Escape) { AccessLevelCheck alc = new AccessLevelCheck(); Console.Clear(); alc.LevelMenuCall(username, password); isUserDeleted = false; } else { SqlCommand cmd2 = new SqlCommand(actionString, con); cmd2.Parameters.AddWithValue("@NewMessage", newMessage); cmd2.Parameters.AddWithValue("@MessageID", messageID); try { Console.Clear(); con.Open(); SqlDataReader drDelete = cmd2.ExecuteReader(); cmd2.Dispose(); con.Close(); isUserDeleted = true; Console.WriteLine($"Message \n{action} {newMessage}! \nOperation successfull!"); Console.ReadKey(); } catch (Exception e) { Console.WriteLine(e.Message + $"Message \n{ action} { newMessage}! \nOperation NOT successfull!"); Console.ReadLine(); isUserDeleted = false; } return(isUserDeleted); } return(isUserDeleted); }
public void MenuUserMessages(List <string> userList, string username, string password, int accessLevel, string action, string actionString) { AccessLevelCheck alc = new AccessLevelCheck(username, password, accessLevel); DBPrintUsers pu = new DBPrintUsers(); SqlConnection con = new SqlConnection(pu.ConncetionString); List <string> listOfUsersString = pu.DBUsersPrintString(username); while (true) { for (int i = 0; i < listOfUsersString.Count; i++) { Console.Clear(); Console.WriteLine(" MESSAGES CLIENT"); Console.WriteLine($" Welcome {username}!"); Console.WriteLine($" Level: {accessLevel}"); Console.WriteLine(); Console.CursorVisible = true; Console.WriteLine("Please Select First User! Press any key to select.."); Console.ReadKey(); Console.CursorVisible = false; var firstUser = Menu.MenuRun(userList, username, accessLevel); #region Main Menus if (firstUser == "Main Menu") { Console.Clear(); alc.LevelMenuCall(username, password); } #endregion #region List Menus else { Console.Clear(); Console.CursorVisible = true; Console.WriteLine($"You selected {firstUser}. Please Select Second User! Press any key to select.."); Console.ReadKey(); Console.CursorVisible = false; listOfUsersString.RemoveAll(x => x.Equals(firstUser)); var secondUser = Menu.MenuRun(listOfUsersString, username, accessLevel); listOfUsersString.Insert(0, firstUser); #region Main Menus if (secondUser == "Main Menu") { Console.Clear(); alc.LevelMenuCall(username, password); } #endregion #region List Menus else { Console.Clear(); Console.WriteLine("MESSAGES"); Console.WriteLine(); Console.WriteLine($"{username.ToUpper()}, you selected to view messages between {firstUser.ToUpper()} and {secondUser.ToUpper()}"); Console.CursorVisible = true; Console.Write("Press any key to Continue. =>To go Back press ESC<= ..."); var key = Console.ReadKey(); Console.CursorVisible = false; if (key.Key == ConsoleKey.Escape) { Console.Clear(); MenuUserMessages(userList, username, password, accessLevel, action, actionString); } else { Console.Clear(); Console.WriteLine(" MESSAGES CLIENT"); Console.WriteLine($" Welcome <{username}>!"); Console.WriteLine(); GetMessages messages = new GetMessages(); List <string> messageList = messages.DBMessagesManipulate(firstUser, secondUser); messageList.Add("Main Menu"); var selectedMessage = Menu.MenuRun(messageList, username, accessLevel); #region Main Menus if (selectedMessage == "Main Menu") { Console.Clear(); alc.LevelMenuCall(username, password); } #endregion else { Console.Clear(); Console.WriteLine(selectedMessage); string[] indexNo = selectedMessage.Split('-'); int MessageID = int.Parse(indexNo[0].Trim()); string newMessage = $"{selectedMessage}"; if (action == "update message") { Console.CursorVisible = true; Console.Write("Please write the new message: "); Console.CursorVisible = false; newMessage = Console.ReadLine(); } DBManipulateMessages mm2 = new DBManipulateMessages(); mm2.MessageManipulate(username, password, action, actionString, newMessage, MessageID); } } } #endregion } #endregion } } }
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 } } }
//MAIN MENU METHOD - Level 1.0 #region MAIN MENU public string MainMenu(List <string> userMenu, string username, string password, int accessLevel) { while (true) { string selectedMenuItem2 = Menu.MenuRun(userMenu, username, accessLevel); DBManipulateUser du = new DBManipulateUser(); //USER MODULES - LEVEL 2 #region USER MODULES #region Send Mail if (selectedMenuItem2 == "Send Mail") { Console.Clear(); DBPrintUsers pu = new DBPrintUsers(); UsersMessages umm = new UsersMessages(); var listOfUsersString = pu.DBUsersPrintString(username); Console.Clear(); umm.MessagesUserPrint(listOfUsersString, username, password, AccessLevel); } #endregion #region Change Password else if (selectedMenuItem2 == "Change Password") { Console.Clear(); Console.WriteLine("Change User's Password"); Console.WriteLine(); Console.Write($"Please Enter your new Password {username}: "); string newPassword = Console.ReadLine().Trim(); string actionString = "Update dbo.Users set Password = @Password where Username = @Username"; du.DBUserManipulate(username, "change Password", actionString, username, password, username, newPassword); } #endregion #region Read Mail //else if (selectedMenuItem2 == "Read Mail") //{ // Console.Clear(); // Console.WriteLine("New Username: "******"New Password: "******"Users Manipulation") { Console.Clear(); UsersActions ua = new UsersActions(); ua.ActionsUsers(superMenu, username, password, accessLevel); } #endregion #region Users Messages Manipulation Menu //else if (selectedMenuItem2 == "Users Messages Manipulation") //{ // Console.Clear(); // UsersActions ua = new UsersActions(); // ua.ActionsUsers(messagesManipulationMenu, username, password, accessLevel); //} #endregion #region Message Manipulation Admin else if (selectedMenuItem2 == "Edit Users Messages") { Console.Clear(); DBPrintUsers pu = new DBPrintUsers(); UsersMessagesMenu umm = new UsersMessagesMenu(); var listOfUsersString = pu.DBUsersPrintString(username); Console.Clear(); string actionString = "Update dbo.Messages set Message = @newMessage where MessageID = @MessageID"; umm.MenuUserMessages(listOfUsersString, username, password, AccessLevel, "update message", actionString); } else if (selectedMenuItem2 == "Delete Users Messages") { Console.Clear(); DBPrintUsers pu = new DBPrintUsers(); UsersMessagesMenu umm = new UsersMessagesMenu(); var listOfUsersString = pu.DBUsersPrintString(username); Console.Clear(); string actionString = "delete From dbo.Messages where MessageID = @MessageID"; umm.MenuUserMessages(listOfUsersString, username, password, AccessLevel, "delete", actionString); } #endregion #region ADMIN USER MENU else if (selectedMenuItem2 == "Users") { Console.Clear(); MenuCall(adminUsersMenu); } #endregion #region Print Users else if (selectedMenuItem2 == "Print Users") { DBPrintUsers pu = new DBPrintUsers(); pu.Printusers(); var listOfUsersString = pu.DBUsersPrintString(username); Console.Clear(); MainMenu(listOfUsersString, Username, Password, accessLevel); } #endregion #region Users Messages else if (selectedMenuItem2 == "View Users Messages") { Console.Clear(); Console.WriteLine("VIEW USERS MESSAGES"); Console.WriteLine(""); DBPrintUsers pu = new DBPrintUsers(); UsersMessages umm = new UsersMessages(); var listOfUsersString = pu.DBUsersPrintString(username); umm.UsersMessagesPrint(listOfUsersString, username, password, AccessLevel); Console.Clear(); } #endregion #endregion //SUPER ADMIN MODULES - LEVEL 4 #region SUPER ADMIN MODULES #region Delete User else if (selectedMenuItem2 == "Delete User") { Console.Clear(); Console.CursorVisible = true; Console.WriteLine("DELETE USER"); Console.WriteLine(); #region DELETE USERNAME INPUT Console.Write("Which User should I Delete for you SuperAdmin: "); string deleteUser = Console.ReadLine().Trim(); DBCheckUser dbc = new DBCheckUser(deleteUser); bool Verify = true; Verify = dbc.DBUserCheck(deleteUser); int i = 0; while ((Verify == false || deleteUser.Length < 1) && i < 2) { i++; Console.Clear(); Console.WriteLine("LOGIN"); Console.WriteLine(); Console.WriteLine($"Username does not Exist. Try another one ({3 - i} more tries):"); Console.Write("Username: "******"delete From dbo.Users where Username = @Username"; dbdu.DBUserManipulate(deleteUser, "delete", actionString, username, password, "", ""); //(deleteUser, username, password, actionString); #endregion } #endregion #endregion #region Update User //else if (selectedMenuItem2 == "Update User") //{ // Console.Clear(); // Console.CursorVisible = true; // Console.WriteLine("Update USER"); // Console.WriteLine(); // #region DELETE USERNAME INPUT // Console.Write("Which User should I Update for you SuperAdmin: "); // string updateUser = Console.ReadLine().Trim(); // DBCheckUser dbc = new DBCheckUser(updateUser); // bool Verify = true; // Verify = dbc.DBUserCheck(updateUser); // int i = 0; // while ((Verify == false || updateUser.Length < 1) && i < 2) // { // i++; // Console.Clear(); // Console.WriteLine("LOGIN"); // Console.WriteLine(); // Console.WriteLine($"Username does not Exist. Try another one ({3 - i} more tries):"); // Console.Write("Username: "******"Create New User") //Adds user to database { Console.Clear(); Console.WriteLine("NEW USER"); Console.CursorVisible = true; Console.Write("New Username: "******"NEW USER SIGNUP"); Console.WriteLine(); Console.WriteLine($"Username is Taken. Try another one ({3 - i} more tries):"); Console.Write("Username: "******"New Password: "******"Confirm New Password: "******"Passwords did not Confirm. {2 - j} tries left. Try again:"); Console.Write("New Password: "******"Confirm New Password: "******""); j++; } Console.Clear(); if (NewPassword == NewPassword2) { AddUser c = new AddUser(NewUsername, NewPassword); AddUser.DBUserAdd(NewUsername, NewPassword); Console.WriteLine($"New User Created with Username: {NewUsername}"); Console.Write($"Press any key to Continue.."); Console.ReadKey(); Console.CursorVisible = false; } } #endregion #region Change User Role else if (selectedMenuItem2 == "Change User Role") { Console.Clear(); Console.WriteLine("USER ROLES"); Console.WriteLine(""); DBPrintUsers pu = new DBPrintUsers(); AssignRoles ar = new AssignRoles(); var listOfUsersString = pu.DBUsersPrintString(username); ar.UserRoles(listOfUsersString, username, password, AccessLevel); Console.Clear(); } #endregion #endregion #region Main Menu else if (selectedMenuItem2 == "Main Menu") { Console.Clear(); AccessLevelCheck alc = new AccessLevelCheck(Username, Password); //, true, true); alc.LevelMenuCall(Username, Password); //MainMenu(superAdminMenu, Username, Password); } #endregion //#endregion //UNIVERSAL MODULES - LEVEL ALL #region UNIVERSAL MODULES #region Logout else if (selectedMenuItem2 == "Logout") { Console.Clear(); MenuCall(); } #endregion #region Exit else if (selectedMenuItem2 == "Exit") { Environment.Exit(0); } #endregion #endregion Console.Clear(); } }
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); } }
public void MessagesUserPrint(List <string> userMenu, string username, string password, int accessLevel) { AccessLevelCheck alc = new AccessLevelCheck(username, password, accessLevel); DBPrintUsers pu = new DBPrintUsers(); List <string> listOfUsersString = pu.DBUsersPrintString(username); while (true) { for (int i = 0; i < listOfUsersString.Count; i++) { Console.Clear(); Console.WriteLine(" MESSAGES CLIENT"); Console.WriteLine($" Welcome {username}!"); Console.WriteLine(); var selectedMenuItem = Menu.MenuRun(userMenu, username, accessLevel); #region Main Menus if (selectedMenuItem == "Main Menu") { Console.Clear(); alc.LevelMenuCall(username, password); } #endregion #region List Menus else { Console.Clear(); Console.WriteLine("MESSAGES"); Console.WriteLine(); Console.WriteLine($"{username}, you selected to send messagee to: {selectedMenuItem}"); Console.CursorVisible = true; Console.Write("Press any key to Continue. =>To go Back press ESC<= ..."); var key = Console.ReadKey(); Console.CursorVisible = false; if (key.Key == ConsoleKey.Escape) { Console.Clear(); MessagesUserPrint(listOfUsersString, username, password, accessLevel); } else { Console.Clear(); GetMessages messages = new GetMessages(); List <string> messageList = messages.DBMessagesPrint(username, selectedMenuItem); messageList.ForEach(Console.WriteLine); Console.CursorVisible = true; Console.Write($"{username} : "); string message = Console.ReadLine(); int j = 0; while ((message.Length > 250) & j < 2) { Console.WriteLine("MESSAGES"); Console.WriteLine(); Console.WriteLine($"Message Too Long. {2 - j} tries left. Try again under 250 characters:"); Console.Write($"{username} :"); message = Console.ReadLine().Trim(); Console.WriteLine(""); j++; } Console.Clear(); if (message.Length > 250) { Console.Clear(); Console.WriteLine("MESSAGES"); Console.WriteLine(); Console.WriteLine("No Message Sent"); Console.Write($"Press any key to Continue.."); Console.ReadKey(); Console.CursorVisible = false; MessagesUserPrint(listOfUsersString, username, password, accessLevel); } else { SendMessage c = new SendMessage(username, selectedMenuItem); SendMessage.DBMessageSend(username, selectedMenuItem, message); Console.WriteLine("MESSAGES"); Console.WriteLine(); Console.WriteLine($"You sent this message to {selectedMenuItem}: {message}"); Console.Write($"Press any key to Continue.."); Console.ReadKey(); Console.CursorVisible = false; } } } #endregion } } }
public string UsersMessagesPrint(List <string> userMenu, string username, string password, int accessLevel) { AccessLevelCheck alc = new AccessLevelCheck(username, password, accessLevel); DBPrintUsers pu = new DBPrintUsers(); SqlConnection con = new SqlConnection(pu.ConncetionString); List <string> listOfUsersString = pu.DBUsersPrintString(username); while (true) { for (int i = 0; i < listOfUsersString.Count; i++) { Console.Clear(); Console.WriteLine(" MESSAGES CLIENT"); Console.WriteLine($" Welcome {username}!"); Console.WriteLine($" Level: {accessLevel}"); Console.WriteLine(); Console.CursorVisible = true; Console.WriteLine("Please Select First User! Press any key to select.."); Console.ReadKey(); Console.CursorVisible = false; var firstUser = Menu.MenuRun(userMenu, username, accessLevel); #region Main Menus if (firstUser == "Main Menu") { Console.Clear(); alc.LevelMenuCall(username, password); } #endregion #region List Menus else { Console.Clear(); Console.CursorVisible = true; Console.WriteLine($"You selected {firstUser}. Please Select Second User! Press any key to select.."); Console.ReadKey(); Console.CursorVisible = false; listOfUsersString.RemoveAll(x => x.Equals(firstUser)); var secondUser = Menu.MenuRun(listOfUsersString, username, accessLevel); #region Main Menus if (secondUser == "Main Menu") { Console.Clear(); alc.LevelMenuCall(username, password); } #endregion #region List Menus else { Console.Clear(); Console.WriteLine("MESSAGES"); Console.WriteLine(); Console.WriteLine($"{username.ToUpper()}, you selected to view messages between {firstUser.ToUpper()} and {secondUser.ToUpper()}"); Console.CursorVisible = true; Console.Write("Press any key to Continue. =>To go Back press ESC<= ..."); var key2 = Console.ReadKey(); Console.CursorVisible = false; if (key2.Key == ConsoleKey.Escape) { Console.Clear(); UsersMessagesPrint(listOfUsersString, username, password, accessLevel); } else { Console.Clear(); GetMessages messages = new GetMessages(); List <string> messageList = messages.DBMessagesPrint(firstUser, secondUser); Console.Clear(); Console.WriteLine("MESSAGES"); Console.WriteLine(); messageList.ForEach(Console.WriteLine); Console.WriteLine(); Console.CursorVisible = true; Console.Write("Press any key to read more Users' Messages. =>To go to Main Menu press ESC<= ..."); var key3 = Console.ReadKey(); Console.CursorVisible = false; if (key3.Key == ConsoleKey.Escape) { Console.Clear(); alc.LevelMenuCall(username, password); } UsersMessagesPrint(listOfUsersString, username, password, accessLevel); } //} #endregion } #endregion } } } }