public static void ViewNewMessage()
        {
            Console.Clear();
            int                SenderId;
            int                userId = ApplicationsMenus.userId;
            string             cmd    = "select id, username from users";
            DatabasesAccess    da     = new DatabasesAccess();
            IEnumerable <User> users  = da.UsersDatabase(cmd);

            cmd = "SELECT * FROM messages WHERE deleted = 0 AND readed = 0;";
            IEnumerable <Message> messages = da.MessagesDatabase(cmd);
            var myMessage = messages.Where(m => m.receiverId == userId).ToList();

            foreach (var m in myMessage)
            {
                SenderId = m.senderId;
                string Sender = HelpMethods.ReturnUsernameFromId(users, SenderId);

                Console.Write("From: ");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Sender);
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(" - Message: " + m.messageData);
                da.ProcessMessagesDatabase(m.id, "Read_messages");
            }
            HelpMethods.ReturnBackMessage();
        }
        public static void ViewAllMessage()
        {
            Console.Clear();
            int                SenderId;
            int                receiverId;
            string             Sender;
            string             receiver;
            string             cmd   = "select id, username from users";
            DatabasesAccess    da    = new DatabasesAccess();
            IEnumerable <User> users = da.UsersDatabase(cmd);

            cmd = "SELECT * FROM messages WHERE deleted = 0";
            IEnumerable <Message> messages = da.MessagesDatabase(cmd);

            foreach (var m in messages)
            {
                SenderId   = m.senderId;
                receiverId = m.receiverId;
                Sender     = HelpMethods.ReturnUsernameFromId(users, SenderId);
                receiver   = HelpMethods.ReturnUsernameFromId(users, receiverId);

                Console.Write("Id: " + m.id + " - From: ");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(Sender);
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(" - To: ");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write(receiver);
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine(" - Message: " + m.messageData);
            }
            HelpMethods.ReturnBackMessage();
        }
Beispiel #3
0
        public static void FindUserName(int SenderId, int receiverId, string message)
        {
            string             Sender;
            string             receiver;
            string             cmd   = "select * from users where deleted = 0";
            DatabasesAccess    da    = new DatabasesAccess();
            IEnumerable <User> users = da.UsersDatabase(cmd);

            cmd = "SELECT * FROM messages WHERE deleted = 0";
            IEnumerable <Message> messages = da.MessagesDatabase(cmd);

            Sender   = ReturnUsernameFromId(users, SenderId);
            receiver = ReturnUsernameFromId(users, receiverId);
            FilesAccess.Files(Sender, receiver, message, SenderId, receiverId);
        }
        public static void EditMessage()
        {
            string                cmd      = "SELECT * FROM messages WHERE deleted = 0";
            DatabasesAccess       da       = new DatabasesAccess();
            IEnumerable <Message> messages = da.MessagesDatabase(cmd);

            Console.Write("Type the id of message you want to update: ");

            int    id;
            string ID     = Console.ReadLine();
            bool   result = int.TryParse(ID, out id);

            if (result)
            {
                bool MessageExist = HelpMethods.CheckExistMessage(id);
                if (MessageExist == true)
                {
                    var senderId = messages
                                   .Where(x => x.id == id)
                                   .Select(x => x.senderId);
                    int SenderId = Convert.ToInt32(senderId.FirstOrDefault());

                    var receiverId = messages
                                     .Where(x => x.id == id)
                                     .Select(x => x.receiverId);
                    int ReceiverId = Convert.ToInt32(receiverId.FirstOrDefault());
                    da.ProcessMessagesDatabase(id, "Delete_messages");
                    Console.Clear();
                    Console.WriteLine($"Write the new message the maximun text limited to 250 characters");
                    Console.WriteLine("\n");
                    HelpMethods.SendMessage(SenderId, ReceiverId);
                }
                else
                {
                    HelpMethods.MessageDoesNotExist();
                }
            }
            else
            {
                HelpMethods.IncorrectMessage();
            }
        }
        public static void ViewMessage()
        {
            string             cmd   = "select id, username from users";
            DatabasesAccess    da    = new DatabasesAccess();
            IEnumerable <User> users = da.UsersDatabase(cmd);

            Console.Write("Type the username you want to read the messages: ");
            string Username  = Console.ReadLine();
            bool   existUser = HelpMethods.CheckExistUser(users, Username);

            if (existUser == true)
            {
                int ReceiverId = HelpMethods.ReturnIdFromUsername(users, Username);
                int userId     = ApplicationsMenus.userId;
                Console.Clear();
                cmd = "SELECT * FROM messages WHERE deleted = 0;";
                IEnumerable <Message> messages = da.MessagesDatabase(cmd);
                var myMessages = messages.Where(m => (m.receiverId == ReceiverId && m.senderId == userId) || (m.senderId == ReceiverId && m.receiverId == userId));

                foreach (var m in myMessages)
                {
                    if (m.senderId == userId)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write("You: ");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine(m.messageData);
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write(Username + ": ");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine(m.messageData);
                    }
                }
                HelpMethods.ReturnBackMessage();
            }
        }