Exemplo n.º 1
0
        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"));
        }