public void PickTwoUsers(string operation, out int senderId, out int receiverId) { Console.Clear(); Various.Header($"{UserRepository.currentUser.Username} : {operation}"); Console.WriteLine(); Various.SystemMessageDirections("Pick two user ids so you can see the messages between them"); ViewAllUsers(); Console.WriteLine(); int userId1 = PickUserExtended(); if (userId1 == -1) { senderId = -1; receiverId = -1; return; } int userId2 = PickUserExtended(); if (userId2 == -1) { senderId = -1; receiverId = -1; return; } senderId = userId1; receiverId = userId2; }
// Type the message public void TypeMessage() { int receiverId = SelectUser(); if (receiverId < 0) { return; } User Receiver = new User(); using (var db = new myContext()) { Receiver = db.Users.Find(receiverId); } Console.Clear(); Various.Header($"{ UserRepository.currentUser.Username} : Send Message to {Receiver.Username}"); string title; string body; // Title Various.SystemMessageDirections("Title must be max 15 characters long"); Console.Write("Type the title of the message: "); title = Various.TypeLetterByLetterWithoutMaskingSTR(15); // Checks if Esc is pressed if (title == "") { Console.WriteLine(); Various.SystemMessage("Send Message Failed"); System.Threading.Thread.Sleep(1500); return; } // Body Console.WriteLine(); Console.WriteLine(); Various.SystemMessageDirections("Body must be max 250 characters long"); Console.Write("Type the body of the message: "); body = Various.TypeLetterByLetterWithoutMaskingSTR(249); // Checks if Esc is pressed if (body == "") { Console.WriteLine(); Various.SystemMessage("Send Message Failed"); System.Threading.Thread.Sleep(1500); return; } MessageRepository.SendMessage(title, body, receiverId); LogRepository.TypeInLog($"{UserRepository.currentUser.Username}", "sent message"); Console.WriteLine(); Various.SystemMessageSuccess("Message Sent Successful"); System.Threading.Thread.Sleep(1500); return; }
public string TitleOrBodyEdit(int messageToBeEditedId, out int choiceToEdit) { Console.Clear(); List <string> TitleOrBodyMenuItems = new List <string> { "Title", "Body", "Exit" }; MenuDesigner TitleOrBodyMenu = new MenuDesigner(TitleOrBodyMenuItems, $"{UserRepository.currentUser.Username} : Edit Message"); int choice = TitleOrBodyMenu.MenuDesign(); Console.WriteLine(); switch (choice) { case 0: // Title Console.Clear(); Various.Header($"{UserRepository.currentUser.Username} : Edit Message : Edit Title"); string title; Console.WriteLine(MessageRepository.ViewMessageWithoutChangingRead(messageToBeEditedId)); Console.WriteLine(); Various.SystemMessageDirections("Title must be max 15 characters long and cannot be void"); Console.Write("Type the title of the message: "); title = Various.TypeLetterByLetterWithoutMaskingSTR(15); // Checks if Esc is pressed if (title == "") { choiceToEdit = -1; return(""); } choiceToEdit = 0; return(title); case 1: // Body Console.Clear(); Various.Header($"{UserRepository.currentUser.Username} : Edit Message : Edit Body"); string body; Console.WriteLine(MessageRepository.ViewMessageWithoutChangingRead(messageToBeEditedId)); Console.WriteLine(); Various.SystemMessageDirections("Body must be max 250 characters long and cannot be void"); Console.Write("Type the body of the message: "); body = Various.TypeLetterByLetterWithoutMaskingSTR(249); // Checks if Esc is pressed if (body == "") { choiceToEdit = -1; return(""); } choiceToEdit = 1; return(body); case 2: choiceToEdit = -1; return(""); default: choiceToEdit = -1; return(""); } }
// Menu Design For Messages public int MenuDesignMessage(out int correctMessageId) { do { Console.Clear(); Console.CursorVisible = false; Various.Header(CurrentLogo); Console.WriteLine(); Various.SystemMessageDirections("Press [1] to sort by Date descending, [2] to sort by Sender name, [3] to sort by Title or [4] to sort by Unread/Read"); Console.WriteLine(); for (i = 0; i < Messages.Count; i++) { // Length Fix int length = 6; if (Messages[i].Body.Length < 6) { length = Messages[i].Body.Length; } if (CurrentItem == i) { if (Messages[i].Read == false) { Console.BackgroundColor = ConsoleColor.DarkMagenta; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"{Messages[i].Date} - From: {Messages[i].Sender.Username} To: {Messages[i].Receiver.Username} - Title: {Messages[i].Title} - Message: {Messages[i].Body.Substring(0,length) + "..."}"); Console.ResetColor(); } else if (Messages[i].Read == true) { Console.BackgroundColor = ConsoleColor.DarkMagenta; Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"{Messages[i].Date} - From: {Messages[i].Sender.Username} To: {Messages[i].Receiver.Username} - Title: {Messages[i].Title} - Message: {Messages[i].Body.Substring(0,length) + "..."}"); Console.ResetColor(); } } else { if (Messages[i].Read == false) { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"{Messages[i].Date} - From: {Messages[i].Sender.Username} To: {Messages[i].Receiver.Username} - Title: {Messages[i].Title} - Message: {Messages[i].Body.Substring(0,length) + "..."}"); Console.ResetColor(); } else if (Messages[i].Read == true) { Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine($"{Messages[i].Date} - From: {Messages[i].Sender.Username} To: {Messages[i].Receiver.Username} - Title: {Messages[i].Title} - Message: {Messages[i].Body.Substring(0,length) + "..."}"); Console.ResetColor(); } } } pressedKey = Console.ReadKey(true); if (pressedKey.Key.ToString() == "DownArrow") { CurrentItem++; if (CurrentItem > Messages.Count - 1) { CurrentItem = 0; } } else if (pressedKey.Key.ToString() == "UpArrow") { CurrentItem--; if (CurrentItem < 0) { CurrentItem = Messages.Count - 1; } } else if (pressedKey.Key == ConsoleKey.Escape) { correctMessageId = -1; return(-1); } else if (pressedKey.KeyChar.ToString() == "1") { Messages = Messages.OrderByDescending(x => x.Date).ToList(); } else if (pressedKey.KeyChar.ToString() == "2") { Messages = Messages.OrderBy(x => x.Sender.Username).ToList(); } else if (pressedKey.KeyChar.ToString() == "3") { Messages = Messages.OrderBy(x => x.Title).ToList(); } else if (pressedKey.KeyChar.ToString() == "4") { Messages = Messages.OrderBy(x => x.Read).ToList(); } } while (pressedKey.Key != ConsoleKey.Enter); correctMessageId = Messages[CurrentItem].Id; return(CurrentItem); }