Exemple #1
0
        // Select all messages between a student and tutor
        public List<MessageDetails> selectMessages(string _studentid, string _tutorid)
        {
            MessageDetails _message = null;
                List<MessageDetails> _messageList = new List<MessageDetails>();
                string selectMessageQuery =     "SELECT * FROM MessageDetails WHERE SenderID = @student AND RecipientID = @tutor " +
                                                "UNION " +
                                                "SELECT * FROM MessageDetails WHERE SenderID = @tutor AND RecipientID = @student " +
                                                "ORDER BY Date DESC, Time DESC;";
                conn = new SqlConnection(DBConnection.ConnectionString);
                using (conn)
                {
                    conn.Open();
                    using (var cmd = conn.CreateCommand())
                    {
                        try
                        {
                            cmd.CommandText = selectMessageQuery;
                            cmd.Prepare();
                            cmd.Parameters.AddWithValue("@student", _studentid);
                            cmd.Parameters.AddWithValue("@tutor", _tutorid);
                            SqlDataReader rdr = cmd.ExecuteReader();

                            while (rdr.Read())
                            {
                                long _messageid = long.Parse(rdr["MessageID"].ToString());
                                string _senderid = rdr["SenderID"].ToString();
                                string _recipientid = rdr["RecipientID"].ToString();
                                DateTime _date = DateTime.Parse(rdr["Date"].ToString());
                                DateTime _time = DateTime.Parse(rdr["Time"].ToString());
                                string _subject = rdr["Subject"].ToString();
                                string _messageContent = rdr["MessageContent"].ToString();
                                _message = new MessageDetails(_messageid, _senderid, _recipientid, _date, _time, _subject, _messageContent);
                                _messageList.Add(_message);
                            }
                            return _messageList;

                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Error: " + e);
                            return null;
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }

                }
        }
Exemple #2
0
 public string getLastInteraction()
 {
     return(MessageDetails.getLatestSentMessageDateOfUser(userID));
 }