예제 #1
0
        public void CreateUserMessage(string usernameLogin, ConsoleColor color)
        {
            Console.Clear();
            Console.WriteLine("======= Create new Message =======");
            Console.WriteLine();
            Console.WriteLine("Please type the username of the recipient of the message:\n");
            string recipient = inputManager.InputUserName();

            if (recipient is null) //if ESC is pressed
            {
                return;
            }

            // check if recipient username exists in database
            bool recipientExists = dBManager.DoesUsernameExist(recipient);

            if (!recipientExists)
            {
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine();
                Console.WriteLine($"A user with username '{recipient}' does not exist.");
                Console.ForegroundColor = color;
                Console.WriteLine("\nPress any key to go back to the user menu");
                Console.ResetColor();
                Console.ReadKey();
            }
            else // the recipient exists. Go on to create and send message
            {
                // check if recipient is active
                bool recipientActive = dBManager.IsUserActive(recipient);
                if (!recipientActive)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("\nThe recipient you chose is no longer active.");
                    Console.WriteLine("Try sending a message to another user.");
                    Console.ForegroundColor = color;
                    Console.WriteLine("\nPress any key to go back to the user menu");
                    Console.ResetColor();
                    Console.ReadKey();
                }
                else
                {
                    messageManager.CreateMessage(usernameLogin, recipient);
                    Console.ForegroundColor = color;
                    Console.WriteLine("\nPress any key to go back to the user menu");
                    Console.ResetColor();
                    Console.ReadKey();
                }
            }
        }
예제 #2
0
        // Method of all Admins to view the messages of a user
        public void ViewUserMessages()
        {
            bool   userExists;
            string usernameToViewMessages;

            do
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("======= Welcome Admin =======");
                Console.ResetColor();
                Console.WriteLine();
                Console.WriteLine("======= Here you can view the users messages =======");
                Console.WriteLine();
                Console.WriteLine("Choose the username of the user you would like to view the messages:");
                usernameToViewMessages = messageInputManager.InputUserName();
                if (usernameToViewMessages is null)
                {
                    return;
                }
                userExists = dBMessageManager.DoesUsernameExist(usernameToViewMessages);
                if (!userExists)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("The username you entered does not exist.\nPlease choose another user.");
                    Console.ResetColor();
                    Console.ReadKey();
                }
                else
                {
                    string   header    = ($"\nWould you like to view the user's sent or received messages?\n");
                    string[] mailboxes = new string[] { "Inbox", "Sent Messages", "Go Back" };
                    do
                    {
                        int option = messageMenuManager.ScrollMenu(header, mailboxes);

                        switch (option)
                        {
                        case 0:
                            ShowInbox(usernameToViewMessages);
                            break;

                        case 1:
                            ShowSentMessages(usernameToViewMessages);
                            break;

                        case 2:
                            return;
                        }
                    } while (true);
                }
            } while (!userExists);
        }