Example #1
0
        public static void Chat(PersonInfo personToMessage)
        {
            string userInput = "";

            while (userInput != "@exit")
            {
                Console.Clear();
                Console.WriteLine("Chatroom");
                Console.WriteLine("Type @exit and press enter to exit");
                Console.WriteLine($"Chatting with {personToMessage.MyFirstName} {personToMessage.MyLastName}:");
                List <PersonInfo> listUsersInRoom = new List <PersonInfo>()
                {
                    CurrentUser.PersonInfo,
                    personToMessage
                };
                // get chat
                List <MessageTable> Messages = Sql.GetAllMessages(CurrentUser.UsersID, personToMessage.UsersID);
                foreach (MessageTable message in Messages)
                {
                    Console.WriteLine($"{listUsersInRoom.FirstOrDefault(e => e.UsersID == message.SenderUsersID).MyFirstName}: {message.MyMessage}");
                }

                userInput = Console.ReadLine();
                MessageTable newMessage = new MessageTable()
                {
                    SenderUsersID    = CurrentUser.UsersID,
                    RecipientUsersID = personToMessage.UsersID,
                    MyMessage        = userInput
                };

                if (userInput != "@exit")
                {
                    Sql.SetMessage(newMessage);
                }
            }
        }