예제 #1
0
        public static void UpdateEmail(UserManager activeUserManager, Message editMessage)
        {
            Console.Write("\n\n\n\n\tNew Title: ");
            string newMessageTitle = Console.ReadLine();

            Console.Write("\n\tNew Body: ");
            string newMessageBody = Console.ReadLine();

            using (var database = new DatabaseStuff())
            {
                try
                {
                    Message newMessage = database.Messages.Single(m => m.Id == editMessage.Id);
                    newMessage.Title  = newMessageTitle;
                    newMessage.Body   = newMessageBody;
                    newMessage.IsRead = false;
                    database.SaveChanges();
                    Console.Write($"\n\n\tEmail updated successfully\n\n\tOK");
                }
                catch (Exception e) { MenuFunctions.PrintException(e); }
                Console.ReadKey(true);
            }
        }
예제 #2
0
        public static void SendEmail(UserManager activeUserManager, User receiver = null, string replyTitle = "")
        {
            string title = "\n\n\tTitle: " + replyTitle;

            // NULL Receiver means it's NOT a REPLY it's just a NEW message.
            if (receiver is null)
            {
                receiver = ManageUserFunctions.SelectUser(activeUserManager);
            }
            if (receiver is null)
            {
                return;
            }

            Console.WriteLine(StringsFormatted.SendEmail);
            Console.Write(title);

            string MessageTitle = (title.Contains("RE")) ? replyTitle : Console.ReadLine();

            Console.Write("\n\tBody: ");
            string MessageBody = Console.ReadLine();

            using (var database = new DatabaseStuff())
            {
                int     senderId = database.Users.Single(i => i.UserName == activeUserManager.UserName).Id;
                Message email    = new Message(senderId, receiver.Id, MessageTitle, MessageBody);
                try
                {
                    database.Messages.Add(email);
                    database.SaveChanges();
                    Console.Write($"\n\n\tEmail sent successfully to {receiver.UserName}\n\n\tOK");
                }
                catch (Exception e) { MenuFunctions.PrintException(e); }
                Console.ReadKey();
            }
        }
예제 #3
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"));
        }