protected void Page_Load(object sender, EventArgs e)
    {
        // check if logged in
        if (Session["user"] == null) // user not logged in
        {
            Session["pageRedirectAfterLogin"] = Request.RawUrl;
            Response.Redirect("Login.aspx"); // transfer to login page
            return;
        }

        if (Request.QueryString["memberInboxID"] == null) // check if inbox is empty
        {
            Response.Redirect("Default.aspx");            // empty redirect to default
            return;
        }

        if (MemberInboxDB.isInboxPresentForMember(Request.QueryString["memberInboxID"].ToString(), MemberDB.getMemberbyEmail(Session["user"].ToString()).MemberID))
        {
            List <MemberMessage> memberMessageList = MemberMessageDB.getMsgforMember(Request.QueryString["memberInboxID"].ToString());

            rptMessages.DataSource = memberMessageList;
            rptMessages.DataBind();

            List <Item> itemInfo = new List <Item>();
            itemInfo.Add(ItemDB.getItembyID(MemberInboxDB.getMemberInboxID(Request.QueryString["memberInboxID"].ToString()).Item.ItemID));
            rptItemInfo.DataSource = itemInfo;
            rptItemInfo.DataBind();
        }
        else
        {
            tbxMessage.Enabled = false;
            btnSend.Enabled    = false;
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Inaccessible Page!')", true);
        }
    }
Beispiel #2
0
 // method to read the column values in the database (through the referenced reader) and assign it to the correct properties of the referenced MemberMessage object
 // allows for easier editing of column names if needed, used only for methods with select statments regarding MemberMessage
 private static void readAMsg(ref MemberMessage msg, ref SqlDataReader reader)
 {
     msg.MemberInbox = MemberInboxDB.getMemberInboxID(reader["memberInboxID"].ToString());
     msg.Reply       = Convert.ToString(reader["reply"]);
     msg.Date        = Convert.ToDateTime(reader["date"]);
     msg.Sender      = MemberDB.getMemberbyID(reader["senderID"].ToString());
 }
    protected void btnContactRenter_Click(object sender, EventArgs e)
    {
        if (Session["user"].ToString() == null)
        {
            Response.Redirect("Login.aspx");
            return;
        }
        else
        {
            // If memberInbox doesnt exist
            if (MemberInboxDB.searchMemberInbox(MemberDB.getMemberbyEmail(Session["user"].ToString()).MemberID, ItemDB.getItembyID(Request.QueryString["itemID"].ToString()).ItemID) == null)
            {
                MemberInbox mem = new MemberInbox();
                mem.Date   = DateTime.Now;
                mem.Item   = ItemDB.getItembyID(Request.QueryString["itemID"]);
                mem.Sender = MemberDB.getMemberbyEmail(Session["user"].ToString());

                int memberInboxID = MemberInboxDB.AddMsgMember(mem);
                Response.Redirect("/inboxMessage.aspx?memberInboxID=" + memberInboxID);
            }

            else
            {
                Response.Redirect("/inboxMessage.aspx?memberInboxID=" + MemberInboxDB.searchMemberInbox(MemberDB.getMemberbyEmail(Session["user"].ToString()).MemberID, ItemDB.getItembyID(Request.QueryString["itemID"].ToString()).ItemID).MemberInboxID);
            }
        }
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (tbxMessage.Text.Length > 255)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Your message cannot exceed 255 characters!')", true);
            return;
        }


        if (tbxMessage.Text != "")
        {
            MemberMessage msgDis = new MemberMessage();

            msgDis.Date        = DateTime.Now;
            msgDis.Reply       = tbxMessage.Text;
            msgDis.Sender      = MemberDB.getMemberbyEmail(Session["user"].ToString());
            msgDis.MemberInbox = MemberInboxDB.getMemberInboxID(Request.QueryString["memberInboxID"].ToString());
            //msgDis.Receiver = MemberDB.getMemberbyID(MemberDB.getMemberbyID("MEM000000001").MemberID);
            //msgDis.Item = ItemDB.getItembyID("ITM000000003");

            MemberMessageDB.AddMsgMember(msgDis);



            tbxMessage.Text = "";

            rptMessages.DataBind();
            Response.Redirect(Request.RawUrl);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // user has selected a message inbox to be viewed. this page displays messages pertaining the message inbox

        // checks if user is logged in
        if (Session["admin"] == null) // if user is not logged in, redirect to login page
        {
            Response.Redirect("Login.aspx");
            return;
        }

        // checks if a message inbox is selected
        if (Request.QueryString["memberInboxID"] == null) // if nothing is selected, redirect back to messageList page
        {
            Response.Redirect("~/messageList.aspx");
        }
        else // if message inbox is selected, display messages pertaining to that message inbox
        {
            List <MemberMessage> memberMessageList = MemberMessageDB.getMsgforMember(Request.QueryString["memberInboxID"].ToString());
            List <MemberInbox>   memberInbox       = new List <MemberInbox>();

            memberInbox.Add(MemberInboxDB.getMemberInboxID(Request.QueryString["memberInboxID"].ToString()));

            lblInboxID.Text = MemberInboxDB.getMemberInboxID(Request.QueryString["memberInboxID"].ToString()).MemberInboxID.ToString();

            rptMemberInfoRedirect.DataSource = memberInbox;
            rptMemberInfoRedirect.DataBind();

            rptMessages.DataSource = memberMessageList;
            rptMessages.DataBind();
        }
    }
 // gets message regarding inbox
 protected string retrieveMessage(string senderID, string reply, string datePosted)
 {
     if (MemberDB.getMemberbyID(senderID).Email == MemberInboxDB.getMemberInboxID(Request.QueryString["memberInboxID"].ToString()).Sender.Email)
     {
         return(" <div class='item '> \n" +
                " <div class='image'> \n" +
                " <img src='assets/images/users/user2.jpg' > \n" +
                " </div> \n" +
                " <div class='text' > \n" +
                " <div class='heading' > \n" +
                " <a href='#'>" + MemberDB.getMemberbyID(senderID).Name + "</a> \n" +
                " <span class='date' >" + datePosted + "</span> \n" +
                " </div> \n" +
                reply + " </div> \n" +
                " </div> \n");
     }
     else
     {
         return(" <div class='item in'> \n" +
                " <div class='image' > \n" +
                " <img src='assets/images/users/user.jpg'> \n" +
                " </div> \n" +
                " <div class='text'> \n" +
                " <div class='heading' > \n" +
                " <a href='#'>" + MemberDB.getMemberbyID(senderID).Name + "</a> \n" +
                " <span class='date' >" + datePosted + "</span> \n" +
                " </div> \n" +
                reply +
                " </div> \n" +
                " </div> \n");
     }
 }
Beispiel #7
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["pageRedirectAfterLogin"] = Request.RawUrl;
            Response.Redirect("Login.aspx");
            return;
        }

        if (Request.QueryString["memberInboxID"] == null)
        {
            Response.Redirect("Default.aspx");
            return;
        }

        List <MemberMessage> memberMessageList = MemberMessageDB.getMsgforMember(Request.QueryString["memberInboxID"].ToString());

        rptMessages.DataSource = memberMessageList;
        rptMessages.DataBind();

        List <Item> itemInfo = new List <Item>();

        itemInfo.Add(ItemDB.getItembyID(MemberInboxDB.getMemberInboxID(Request.QueryString["memberInboxID"].ToString()).Item.ItemID));
        rptItemInfo.DataSource = itemInfo;
        rptItemInfo.DataBind();
    }
Beispiel #8
0
    // method to get MemberMessage by memberInboxID from the database
    public static List <MemberMessage> getMsgforMember(string memberInboxID)
    {
        List <MemberMessage> msgDisList = new List <MemberMessage>();

        try
        {
            SqlCommand command = new SqlCommand("SELECT * FROM MemberMessage WHERE memberInboxID = @memberInboxID");
            command.Parameters.AddWithValue("@memberInboxID", memberInboxID);
            command.Connection = connection;
            connection.Open();

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                MemberMessage msgDis = new MemberMessage();

                msgDis.Date  = Convert.ToDateTime(reader["date"]);
                msgDis.Reply = reader["reply"].ToString();

                if (reader["memberInboxID"] != DBNull.Value)
                {
                    msgDis.MemberInbox = MemberInboxDB.getMemberInboxID(reader["memberInboxID"].ToString());
                }
                else
                {
                    msgDis.MemberInbox = new MemberInbox(0, new DateTime(), new Member(), new Item());
                }

                if (reader["senderID"] != DBNull.Value)
                {
                    msgDis.Sender = MemberDB.getMemberbyID(reader["senderID"].ToString());
                }
                else
                {
                    msgDis.Sender = new Member(null, null, null, 0, null, null, 0, null, null, new DateTime(), new DateTime(), null, new DateTime(), null, null);
                }

                msgDisList.Add(msgDis);
            }
            reader.Close();
        }
        finally
        {
            connection.Close();
        }
        return(msgDisList);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // displays a full list of message inbox between members

        // checks if user is logged in
        if (Session["admin"] == null) // if user is not logged in, redirect to login page
        {
            Response.Redirect("Login.aspx");
            return;
        }

        List <MemberInbox> memberInboxList = MemberInboxDB.getAllMemberInbox();

        rptMemberMessage.DataSource = memberInboxList;
        rptMemberMessage.DataBind();
    }
Beispiel #10
0
    protected void btnContactRenter_Click(object sender, EventArgs e)
    {
        // check if logged in
        if (Session["user"] == null) // user not logged in
        {
            Session["pageRedirectAfterLogin"] = Request.RawUrl;
            Response.Redirect("Login.aspx"); // transfer to login page
            return;
        }

        // allow Rentee to contact Renter
        Item item = ItemDB.getItembyID(Request.QueryString["itemID"].ToString());

        if (item.Renter.Email == Session["user"].ToString())
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Cannot message yourself!')", true);

            return;
        }
        // must be logged in to contact Renter
        if (Session["user"] == null)
        {
            Response.Redirect("Login.aspx");
            return;
        }
        else
        {
            // If memberInbox doesnt exist
            if (MemberInboxDB.searchMemberInbox(MemberDB.getMemberbyEmail(Session["user"].ToString()).MemberID, ItemDB.getItembyID(Request.QueryString["itemID"].ToString()).ItemID).MemberInboxID == -1)
            { // creates and send message
                MemberInbox mem = new MemberInbox();
                mem.Date   = DateTime.Now;
                mem.Item   = ItemDB.getItembyID(Request.QueryString["itemID"]);
                mem.Sender = MemberDB.getMemberbyEmail(Session["user"].ToString());

                int memberInboxID = MemberInboxDB.AddMsgMember(mem);
                Response.Redirect("/inboxMessage.aspx?memberInboxID=" + memberInboxID);
            }

            else
            {
                Response.Redirect("/inboxMessage.aspx?memberInboxID=" + MemberInboxDB.searchMemberInbox(MemberDB.getMemberbyEmail(Session["user"].ToString()).MemberID, ItemDB.getItembyID(Request.QueryString["itemID"].ToString()).ItemID).MemberInboxID);
            }
        }
    }
Beispiel #11
0
 private List <MemberInbox> getMessageOfThisMember()
 {
     return(MemberInboxDB.getAllMemberInboxByID(MemberDB.getMemberbyEmail(Session["user"].ToString())));
 }