Exemplo n.º 1
0
        // Helper method for filling dummy data into the Conversation table
        protected void btnInsertCommand_Click(object sender, EventArgs e)
        {
            Conversation newConvo = new Conversation();

            newConvo.ParticipantA_ID = 12;
            newConvo.ParticipantB_ID = 1;

            Message msg1 = new Message();
            msg1.SenderID = 12;
            msg1.Timestamp = DateTime.Now;
            msg1.Content = "How did you get on on Saturday";

            Message msg2 = new Message();
            msg2.SenderID = 1;
            msg2.Timestamp = DateTime.Now;
            msg2.Content = "What was on Saturday?";

            Message msg3 = new Message();
            msg3.SenderID = 1;
            msg3.Timestamp = DateTime.Now;
            msg3.Content = "Wait, oh the cinema. Yeah it was nice. Good movie, highly recommended.";

            Message msg4 = new Message();
            msg4.SenderID = 12;
            msg4.Timestamp = DateTime.Now;
            msg4.Content = "Which film was it again?";

            newConvo.MessagesList.Add(msg1);
            newConvo.MessagesList.Add(msg2);
            newConvo.MessagesList.Add(msg3);
            newConvo.MessagesList.Add(msg4);

            messageManager.InsertIntoConvoTable(newConvo);
        }
Exemplo n.º 2
0
        public bool AddNewConversation(Conversation newConvo)
        {
            bool isAddedSuccessfully = false;

            try
            {
                messageManager = new DALMessageMngr();

                if (messageManager.AddNewConversation(newConvo))
                {
                    isAddedSuccessfully = true;
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return isAddedSuccessfully;
        }
Exemplo n.º 3
0
        protected void imgBtnSendMessage_Click(object sender, ImageClickEventArgs e)
        {
            /*
             * This button does three things:
             *  1. It saves the latest message to selectedConvo.MessageList.
             *  2. It sends the entire conversation to the database to be refreshed and then stored.
             *  3. It refreshes the repeater.
             *
             * The second point seems excessive as there will therefore be a database call every time
             * a message is sent. But for users who expect to be able to message one another,
             * a narrow frame of time between messages being sent and received,
             * and therefore stored in the database and fetched, is essential.
             * */

            try
            {
                // Point 1.
                Message newMessage = new Message();
                newMessage.SenderID = user.ID;
                newMessage.Timestamp = DateTime.Now;
                newMessage.Content = txtNewMessage.Text;

                selectedConversation.MessagesList.Add(newMessage);

                // Point 2.
                selectedConversation = messageManager.UpdateConvoTable(selectedConversation);

                // Point 3.
                PopulateMessageThread(selectedConversation);

                txtNewMessage.Text = "";
            }
            catch (Exception)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "alert('Error sending message. Message not delivered.')", true);
                throw;
            }
        }
Exemplo n.º 4
0
 protected void closeThisMessage_Click1(object sender, EventArgs e)
 {
     MessageThread.Visible = false;
     mySummaries.Visible = true;
     selectedConversation = null;
 }
Exemplo n.º 5
0
 private void PopulateMessageThread(Conversation convo)
 {
     /* This fills rptconvoMessages with all the messages in selectedConvo
      * and assigns CSS classes according to the message's sender.
      * */
     rptconvoMessages.DataSource = convo.MessagesList;
     rptconvoMessages.DataBind();
 }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Instantiate selectedConversation, if required.
                if (selectedConversation == null)
                {
                    selectedConversation = new Conversation();
                }

                // Check if query string contains ConversationID value
                String selectedConvoID = Request.ServerVariables["QUERY_STRING"];

                if (selectedConvoID.Length > 0 && conversationList.Count > 0)
                {
                    /* If a conversation was selected, retreive the selected conversation
                     * according to its ID in conversation<List> and present its messages to the user.
                     * */
                    int selectedIDasInt;
                    if (int.TryParse(selectedConvoID, out selectedIDasInt))
                    {
                        for (int i = 0; i < conversationList.Count; i++)
                        {
                            if (conversationList.ElementAt(i).ConversationID.Equals(selectedIDasInt))
                            {
                                selectedConversation = conversationList.ElementAt(i);
                                break;
                            }
                        }

                        mySummaries.Visible = false;
                        MessageThread.Visible = true;
                        PopulateMessageThread(selectedConversation);
                    }
                }
            try
            {
                userManager = new BLLUserMngr();
                user = userManager.BLLGetCurrentUser(Session);

                messageManager = new BLLMessageMngr(user.ID);
                getMessages();
            }
            catch (Exception)
            {
                //Log error
                Response.Redirect("404.aspx");
            }
        }
Exemplo n.º 7
0
 public Conversation UpdateConvoTable(Conversation selectedConvo)
 {
     selectedConvo = messageManager.UpdateConvoTable(selectedConvo);
     return selectedConvo;
 }
Exemplo n.º 8
0
 public void InsertIntoConvoTable(Conversation newConvo)
 {
     messageManager.InsertIntoConvoTable(newConvo);
 }