public static void ViewAllMessage() { Console.Clear(); int SenderId; int receiverId; string Sender; string receiver; string cmd = "select id, username from users"; DatabasesAccess da = new DatabasesAccess(); IEnumerable <User> users = da.UsersDatabase(cmd); cmd = "SELECT * FROM messages WHERE deleted = 0"; IEnumerable <Message> messages = da.MessagesDatabase(cmd); foreach (var m in messages) { SenderId = m.senderId; receiverId = m.receiverId; Sender = HelpMethods.ReturnUsernameFromId(users, SenderId); receiver = HelpMethods.ReturnUsernameFromId(users, receiverId); Console.Write("Id: " + m.id + " - From: "); Console.ForegroundColor = ConsoleColor.Green; Console.Write(Sender); Console.ForegroundColor = ConsoleColor.White; Console.Write(" - To: "); Console.ForegroundColor = ConsoleColor.Green; Console.Write(receiver); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" - Message: " + m.messageData); } HelpMethods.ReturnBackMessage(); }
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 UserMenu() { Console.WriteLine("USER MENU - Please choose an option."); Console.WriteLine("===================================="); Console.WriteLine("a. Create new User"); Console.WriteLine("b. View Users"); Console.WriteLine("c. Delete Users"); Console.WriteLine("d. Update Username "); Console.WriteLine("e. Update Password"); Console.WriteLine("f. Update Role"); Console.Write("\n"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Enter an option: "); Console.ForegroundColor = ConsoleColor.White; string choice = Console.ReadLine(); if (editUser.ContainsKey(choice)) { Console.Clear(); editUser[choice](); } else { HelpMethods.IncorrectMessage(); } }
public static void DeleteMessage() { Console.Write("Type the id of message you want to delete: "); int id; string ID = Console.ReadLine(); bool result = int.TryParse(ID, out id); DatabasesAccess da = new DatabasesAccess(); if (result) { bool MessageExist = HelpMethods.CheckExistMessage(id); if (MessageExist == true) { Console.Clear(); da.ProcessMessagesDatabase(id, "Delete_messages"); } else { HelpMethods.MessageDoesNotExist(); } } else { HelpMethods.IncorrectMessage(); } }
public static string RoleMenu() { while (true) { Console.WriteLine("ROLES MENU - Please choose an option."); Console.WriteLine("====================================="); Console.WriteLine("a. Set User"); Console.WriteLine("b. Set Admin with View Privilege"); Console.WriteLine("c. Set Admin with View and Edit Privilege"); Console.WriteLine("d. Set Admin with View, Edit and Delete Privilege"); Console.WriteLine("e. Set Super Admin"); Console.Write("\n"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Enter an option: "); Console.ForegroundColor = ConsoleColor.White; string key = Console.ReadLine(); if (roles.ContainsKey(key)) { Console.Clear(); return(roles[key]); } else { HelpMethods.IncorrectMessage(); } } }
public string ProcedureDatabases(string username, string password, string nameProcedure) { string user; SqlConnection dbcon = new SqlConnection(connectionString); try { using (dbcon) { dbcon.Open(); var parameters = new DynamicParameters(); parameters.Add("@username", username); parameters.Add("@pass", password); parameters.Add("@user", null, size: 100, direction: ParameterDirection.Output); dbcon.Execute(nameProcedure, parameters, commandType: CommandType.StoredProcedure); user = parameters.Get <string>("@user"); } } catch (SqlException) { HelpMethods.MessageErrorConnection(); user = ""; } return(user); }
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 ViewNewMessage() { Console.Clear(); int SenderId; int userId = ApplicationsMenus.userId; string cmd = "select id, username from users"; DatabasesAccess da = new DatabasesAccess(); IEnumerable <User> users = da.UsersDatabase(cmd); cmd = "SELECT * FROM messages WHERE deleted = 0 AND readed = 0;"; IEnumerable <Message> messages = da.MessagesDatabase(cmd); var myMessage = messages.Where(m => m.receiverId == userId).ToList(); foreach (var m in myMessage) { SenderId = m.senderId; string Sender = HelpMethods.ReturnUsernameFromId(users, SenderId); Console.Write("From: "); Console.ForegroundColor = ConsoleColor.Green; Console.Write(Sender); Console.ForegroundColor = ConsoleColor.White; Console.Write(" - Message: " + m.messageData); da.ProcessMessagesDatabase(m.id, "Read_messages"); } HelpMethods.ReturnBackMessage(); }
public static void Login() { bool foundPassword = false; string cmd = "select id, username, role, deleted from users"; DatabasesAccess da = new DatabasesAccess(); HelpMethods.LoginScreenMessage(); Console.Write("Username: "******"\n"); Console.Clear(); ApplicationsMenus.ApplicationMenu(myUser); } else { HelpMethods.LoginScreenMessage(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Incorrect username"); Console.ForegroundColor = ConsoleColor.White; Console.Write("Username: "); username = Console.ReadLine(); } } }
public static bool Password(String username) { bool foundPassword = false; DatabasesAccess da = new DatabasesAccess(); while (foundPassword == false) { string password = Mask(); Console.WriteLine("\n"); string correct = da.ProcedureDatabases(username, password, "check_Password"); if (correct != username) { HelpMethods.LoginScreenMessage(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Incorrect password try again"); Console.ForegroundColor = ConsoleColor.White; password = ""; } else { foundPassword = true; } } return(foundPassword); }
public static void ViewUser() { string cmd = "select username, role from users where deleted = 0"; DatabasesAccess da = new DatabasesAccess(); IEnumerable <User> users = da.UsersDatabase(cmd); Console.WriteLine("The users are:"); Console.Write("\n"); foreach (var u in users) { Console.WriteLine("Username: "******" - " + "Role: " + u.role); } HelpMethods.ReturnBackMessage(); }
public static void EditMessage() { string cmd = "SELECT * FROM messages WHERE deleted = 0"; DatabasesAccess da = new DatabasesAccess(); IEnumerable <Message> messages = da.MessagesDatabase(cmd); Console.Write("Type the id of message you want to update: "); int id; string ID = Console.ReadLine(); bool result = int.TryParse(ID, out id); if (result) { bool MessageExist = HelpMethods.CheckExistMessage(id); if (MessageExist == true) { var senderId = messages .Where(x => x.id == id) .Select(x => x.senderId); int SenderId = Convert.ToInt32(senderId.FirstOrDefault()); var receiverId = messages .Where(x => x.id == id) .Select(x => x.receiverId); int ReceiverId = Convert.ToInt32(receiverId.FirstOrDefault()); da.ProcessMessagesDatabase(id, "Delete_messages"); Console.Clear(); Console.WriteLine($"Write the new message the maximun text limited to 250 characters"); Console.WriteLine("\n"); HelpMethods.SendMessage(SenderId, ReceiverId); } else { HelpMethods.MessageDoesNotExist(); } } else { HelpMethods.IncorrectMessage(); } }
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 IEnumerable <Message> MessagesDatabase(string cmd) { IEnumerable <Message> messages; SqlConnection dbcon = new SqlConnection(connectionString); try { using (dbcon) { dbcon.Open(); messages = dbcon.Query <Message>(cmd).ToList(); } } catch (SqlException) { HelpMethods.MessageErrorConnection(); messages = null; } return(messages); }
public static void CreateUser() { Dictionary <string, string> DBDictionary = new Dictionary <string, string>(); Console.Write("Type the username: "******"@username", username); DBDictionary.Add("@pass", password); DBDictionary.Add("@role", role); da.ProcedureDatabase(DBDictionary, "Insert_Users"); } }
public void ProcessMessagesDatabase(int Id, string nameProcedure) { SqlConnection dbcon = new SqlConnection(connectionString); try { using (dbcon) { dbcon.Open(); var parameters = new DynamicParameters(); parameters.Add("id", Id); var affectedRows = dbcon.Execute(nameProcedure, parameters, commandType: CommandType.StoredProcedure); //Console.WriteLine($"{affectedRows} Affected Rows"); } } catch (SqlException) { HelpMethods.MessageErrorConnection(); } }
public void InsertMessagesDatabase(int userId, int receiverId, string message) { SqlConnection dbcon = new SqlConnection(connectionString); try { using (dbcon) { dbcon.Open(); var parameters = new DynamicParameters(); parameters.Add("@senderId", userId); parameters.Add("@receiverId", receiverId); parameters.Add("@messageData", message); var affectedRows = dbcon.Execute("Insert_messages", parameters, commandType: CommandType.StoredProcedure); //Console.WriteLine($"{affectedRows} Affected Rows"); } } catch (SqlException) { HelpMethods.MessageErrorConnection(); } }
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(); } }
public static void ApplicationMenu(User myUser) { Users user; Dictionary <string, Users> TypeOfUsers = new Dictionary <string, Users>() { { "User", new User(myUser.username, myUser.id) }, { "View Admin", new ViewAdmin(myUser.username, myUser.id) }, { "View-Edit Admin", new ViewEditAdmin(myUser.username, myUser.id) }, { "View-Edit-Delete Admin", new ViewEditDeleteAdmin(myUser.username, myUser.id) }, { "Super Admin", new SuperAdmin(myUser.username, myUser.id) } }; user = TypeOfUsers[myUser.role]; userId = user.id; Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Welcome {myUser.username}"); Console.ForegroundColor = ConsoleColor.White; Console.Write("\n"); while (true) { user.PublicMenu(); Console.Write("\n"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Enter an option: "); Console.ForegroundColor = ConsoleColor.White; string choice = Console.ReadLine(); if (user.application.ContainsKey(choice)) { Console.Clear(); user.application[choice](); } else { HelpMethods.IncorrectMessage(); } } }
public void ProcedureDatabase(Dictionary <string, string> DBDictionary, string nameProcedure) { SqlConnection dbcon = new SqlConnection(connectionString); try { using (dbcon) { dbcon.Open(); var parameters = new DynamicParameters(); foreach (var d in DBDictionary) { parameters.Add(d.Key, d.Value); } var affectedRows = dbcon.Execute(nameProcedure, parameters, commandType: CommandType.StoredProcedure); //Console.WriteLine($"{affectedRows} Affected Rows"); } } catch (SqlException) { HelpMethods.MessageErrorConnection(); } }
public static void ChatMenu() { Console.WriteLine("CHAT MENU - Please choose an option."); Console.WriteLine("===================================="); Console.WriteLine("a. Send Message"); Console.WriteLine("b. Read Messages"); Console.WriteLine("c. Read New Messages"); Console.WriteLine("d. Read All Messages"); Console.Write("\n"); Console.ForegroundColor = ConsoleColor.Green; Console.Write("Enter an option: "); Console.ForegroundColor = ConsoleColor.White; string choice = Console.ReadLine(); if (menuMessages.ContainsKey(choice)) { Console.Clear(); menuMessages[choice](); } else { HelpMethods.IncorrectMessage(); } }