Example #1
0
 public string GetUsername(int userid)
 {
     if (!usernames.ContainsKey(userid))             // Caching in dictionary to reduce DB calls
     {
         string username = Authenticate.ConvertIdToUsername(userid);
         usernames.Add(userid, username);
         return(username);
     }
     else
     {
         return(usernames[userid]);
     }
 }
Example #2
0
        protected void ButtonChooseRecipient_Click(object sender, EventArgs e)
        {
            int    otherid   = -1;
            int    currentid = CurrentUser.GetUserId();
            string username;

            // Validate Username
            if (string.IsNullOrWhiteSpace(ReceiverId.Text))
            {
                Msg.Text = "Username entered is empty";
                return;
            }
            else
            {
                otherid  = Authenticate.ConvertUsernameToId(ReceiverId.Text);
                username = ReceiverId.Text;
            }

            // Validate UserID exists
            if (otherid == -1)
            {
                Msg.Text = "No recipient by this username was found";
                return;
            }
            else if (otherid == currentid)
            {
                Msg.Text = "You cannot start a conversation with yourself!";
                return;
            }
            else if (otherid != currentid && otherid > 0)
            {
                ViewState["thisParty"]  = CurrentUser.GetUserId();
                ViewState["otherParty"] = otherid;

                ToggleWindows();
                LblRecipient.Text       = Authenticate.ConvertIdToUsername(otherid);
                ChatRepeater.DataSource = RetrieveMessages(otherid);
                ChatRepeater.DataBind();
                return;
            }
        }