public static void SendMessage() { string cmd = "select id, username from users where deleted = 0"; DatabasesAccess da = new DatabasesAccess(); IEnumerable <User> users = da.UsersDatabase(cmd); Console.Write("Type the username you want to exchange messages: "); string Username = Console.ReadLine(); bool UserExist = HelpMethods.CheckExistUser(users, Username); if (UserExist == true) { int ReceiverId = HelpMethods.ReturnIdFromUsername(users, Username); int userId = ApplicationsMenus.userId; Console.Clear(); Console.Write($"Write a message to "); Console.ForegroundColor = ConsoleColor.Green; Console.Write(Username); Console.ForegroundColor = ConsoleColor.White; Console.Write(", the maximun text limited to 250 characters"); Console.WriteLine("\n"); HelpMethods.SendMessage(userId, ReceiverId); } else { HelpMethods.UserDoesNotExistMessage(); } }
public static void UpdateUserName() { Dictionary <string, string> DBDictionary = new Dictionary <string, string>(); Console.Write("Type the username you want to update: "); DatabasesAccess da = new DatabasesAccess(); string username = Console.ReadLine(); bool userNotExist; bool UserExist = HelpMethods.CheckExistUser(username); if (UserExist == true) { Console.Clear(); Console.Write("Type a new username: "******"username", username); DBDictionary.Add("newUsername", newUsername); da.ProcedureDatabase(DBDictionary, "Update_UserName"); } } else { HelpMethods.UserDoesNotExistMessage(); } }
public static void DeleteUser() { Dictionary <string, string> DBDictionary = new Dictionary <string, string>(); Console.Write("Type the username you want to delete: "); string username = Console.ReadLine(); bool UserExist = HelpMethods.CheckExistUser(username); DatabasesAccess da = new DatabasesAccess(); if (UserExist == true) { Console.Clear(); DBDictionary.Add("@username", username); da.ProcedureDatabase(DBDictionary, "Delete_Users"); } else { HelpMethods.UserDoesNotExistMessage(); } }
public static void ViewMessage() { string cmd = "select id, username from users"; DatabasesAccess da = new DatabasesAccess(); IEnumerable <User> users = da.UsersDatabase(cmd); Console.Write("Type the username you want to read the messages: "); string Username = Console.ReadLine(); bool existUser = HelpMethods.CheckExistUser(users, Username); if (existUser == true) { int ReceiverId = HelpMethods.ReturnIdFromUsername(users, Username); int userId = ApplicationsMenus.userId; Console.Clear(); cmd = "SELECT * FROM messages WHERE deleted = 0;"; IEnumerable <Message> messages = da.MessagesDatabase(cmd); var myMessages = messages.Where(m => (m.receiverId == ReceiverId && m.senderId == userId) || (m.senderId == ReceiverId && m.receiverId == userId)); foreach (var m in myMessages) { if (m.senderId == userId) { Console.ForegroundColor = ConsoleColor.Green; Console.Write("You: "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(m.messageData); } else { Console.ForegroundColor = ConsoleColor.Green; Console.Write(Username + ": "); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(m.messageData); } } HelpMethods.ReturnBackMessage(); } }
public static void UpdateRole() { Dictionary <string, string> DBDictionary = new Dictionary <string, string>(); Console.Write("Type the username you want to update: "); string username = Console.ReadLine(); bool UserExist = HelpMethods.CheckExistUser(username); DatabasesAccess da = new DatabasesAccess(); if (UserExist == true) { Console.Clear(); string role = ApplicationsMenus.RoleMenu(); DBDictionary.Add("username", username); DBDictionary.Add("newRole", role); da.ProcedureDatabase(DBDictionary, "Update_Users_By_Role"); } else { HelpMethods.UserDoesNotExistMessage(); } }