public static void DeleteUser(User deletingUser) { if (Menus.HorizontalMenu("\n\n\tAre you sure you want to delete this user?", new List <string> { "Yes", "No" }).Contains('Y')) { using (var database = new DatabaseStuff()) { // When deleting a user you have to erase their emails and chat messages as well database.Users.Remove(database.Users.Single(i => i.UserName == deletingUser.UserName)); var deletingMessages = database.Messages.Where(i => i.ReceiverId == deletingUser.Id || i.SenderId == deletingUser.Id); foreach (Message deletingMessage in deletingMessages) { database.Messages.Remove(deletingMessage); } var deletingChatMessages = database.Chat.Where(i => i.SenderId == deletingUser.Id); foreach (ChatMessage deletingChatMessage in deletingChatMessages) { database.Chat.Remove(deletingChatMessage); } database.SaveChanges(); } Console.Clear(); Console.WriteLine("\n\n\tUser successfully DELETED\n\n\tOK"); Console.ReadKey(); } }
public static void DeleteChatMessage(int chosenMessageID) { if (Menus.HorizontalMenu("\n\n\tAre you sure you want to delete the selected messages?", new List <string> { "Yes", "No" }).Contains('Y')) { using (var database = new DatabaseStuff()) { database.Chat.Remove(database.Chat.Single(c => c.Id == chosenMessageID)); database.SaveChanges(); } } }
public static void DeleteMessage(Message receivedMessage) { if (Menus.HorizontalMenu("\n\n\tAre you sure you want to delete this message?", new List <string> { "Yes", "No" }).Contains('Y')) { using (var database = new DatabaseStuff()) { database.Messages.Remove(database.Messages.Single(i => i.Id == receivedMessage.Id)); database.SaveChanges(); Console.Clear(); Console.WriteLine("\n\n\tMessage successfully DELETED\n\n\tOK"); Console.ReadKey(); } } }
public static void DeleteAllChatMessages() { if (Menus.HorizontalMenu("\n\n\tAre you sure you want to delete ALL chat messages?", new List <string> { "Yes", "No" }).Contains('Y')) { using (var database = new DatabaseStuff()) { // When deleting all the contents of a table the ExecuteSqlCommand // is used for execution speed purposes. database.Database.ExecuteSqlCommand("DELETE FROM ChatMessages"); database.SaveChanges(); } Console.Clear(); Console.WriteLine("\n\n\tCHAT successfully DELETED\n\n\tOK"); Console.ReadKey(); } }
public static UserManager LoginScreen() { while (true) { string userChoice = Menus.HorizontalMenu(StringsFormatted.Welcome, new List <string> { "Sign Up", "Log In" }); using (var database = new DatabaseStuff()) { if (userChoice == "Log In") { try { return(SuccessfullLogin(isNewUser: false)); } catch (Exception e) { PrintException(e); } } else { try { return(SuccessfullLogin(isNewUser: true)); } catch (Exception e) { PrintException(e); } } } } }
public static void ShowChat(UserManager activeUserManager) { while (true) { Console.Clear(); string chat = StringsFormatted.Chat + "\n\n"; using (var database = new DatabaseStuff()) { // Access the active user from Database User activeUser = database.Users.Single(u => u.UserName == activeUserManager.UserName); // Get all the chat messages ordered increasingly and // access the users haven't read them yet. List <ChatMessage> chatMessages = database.Chat.Include("UnreadUsers").OrderBy(i => i.Id).ToList(); bool firstNewMessage = true; foreach (ChatMessage message in chatMessages) { if (message.UnreadUsers.Contains(activeUser) && firstNewMessage) { chat += "\n\t__________________________NEW__________________________\n"; firstNewMessage = false; } chat += "\n\t" + message.TimeSent.ToString("dd/MM HH:mm") + " " + (database.Users.Single(i => i.Id == message.SenderId).UserName.ToString() + ":").PadRight(15) + message.Text + '\n'; } // Since by the next point the user read the new messages activeUserManager.ClearUnreadChat(); List <string> chatOptions = new List <string> { "Reply", "Back" }; if (activeUser.UserAccess == Accessibility.administrator && database.Chat.Any()) { chatOptions.Insert(1, "Edit"); chatOptions.Insert(2, "Delete All"); } string userChoice = Menus.HorizontalMenu(chat, chatOptions); // Does the user wish to leave? if (userChoice.Contains("Back")) { break; } // Or edit the chat Messages else if (userChoice.Contains("Edit")) { ChatFunctions.EditChatMessages(); } // Maybe delete them all? else if (userChoice.Contains("Delete All")) { ChatFunctions.DeleteAllChatMessages(); } // Or add a reply else { ChatFunctions.AddReplyToChat(activeUserManager, chat); } } } }
public static void PresentAndManipulateMessage(UserManager activeUserManager, List <Message> Messages, bool Received = true) { string userChoice; do { if (Messages.Count == 0) { MenuFunctions.PrintNoContent("No Messages to View"); return; } Message selectedMessage = SelectMessage(activeUserManager, Messages, Received); if (selectedMessage is null) { return; } string presentedMessage = StringsFormatted.ReadEmails + $"\n\n\tTitle: {selectedMessage.Title}" + $"\n\n\tBody: {selectedMessage.Body}\n\n"; List <string> messageOptions = new List <string> { "Forward", "Delete", "Back" }; if (Received) { messageOptions.Insert(0, "Reply"); } else { messageOptions.Insert(0, "Edit"); } userChoice = Menus.HorizontalMenu(presentedMessage, messageOptions); using (var database = new DatabaseStuff()) { Message readMessage = database.Messages.Single(m => m.Id == selectedMessage.Id); if (Received) { readMessage.IsRead = true; } database.SaveChanges(); if (userChoice.Contains("Forward")) { ForwardMessage(activeUserManager, selectedMessage); } else if (userChoice.Contains("Reply")) { User toBeReplied = database.Users.Single(u => u.Id == readMessage.Sender.Id); SendEmail(activeUserManager, toBeReplied, "RE: " + readMessage.Title); } else if (userChoice.Contains("Edit")) { UpdateEmail(activeUserManager, selectedMessage); } else if (userChoice.Contains("Delete")) { DeleteMessage(selectedMessage); return; } } }while (!userChoice.Contains("Back")); }