Example #1
0
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            string searchTerm = TBSearch.Text;

            if (string.IsNullOrWhiteSpace(searchTerm))
            {
                LSearchTitle.Text = "Search results for \"" + searchTerm + "\"";
                LSearchEmpty.Text = "0";
                return;
            }

            SearchPanel.Visible = true;

            searchTerm = searchTerm.ToLower();


            WebRequest  request  = WebRequest.Create(path + "SearchForFriends/" + otherPersonId + "/" + searchTerm);
            WebResponse response = request.GetResponse();


            Stream       theDataStream = response.GetResponseStream();
            StreamReader reader        = new StreamReader(theDataStream);
            String       data          = reader.ReadToEnd();

            reader.Close();
            response.Close();

            JavaScriptSerializer js = new JavaScriptSerializer();


            User[] friends = js.Deserialize <User[]>(data);

            for (int i = 0; i < friends.Length; i++)
            {
                // if self

                if (friends[i].UserId == userId)
                {
                    SelfCard ctrl = (SelfCard)LoadControl("SelfCard.ascx");

                    ctrl.FirstName = friends[i].FirstName.ToString();
                    ctrl.LastName  = friends[i].LastName.ToString();

                    int friendId = int.Parse(friends[i].UserId.ToString());
                    ctrl.UserId = friendId;
                    // if no profile pic, load default
                    string profilePicture = GetProfilePicture(friendId);
                    ctrl.ImageUrl = profilePicture;

                    ctrl.UserId = int.Parse(friends[i].UserId.ToString());

                    // bind data to ctrl
                    ctrl.DataBind();

                    // add to panel
                    SearchPanel.Controls.Add(ctrl);
                }
                else   // if not self


                // check if friend and load friend card if theyre friends
                {
                    bool areFriends = AreFriends(friends[i].UserId);

                    if (!areFriends)
                    {
                        NonFriendCard ctrl = (NonFriendCard)LoadControl("NonFriendCard.ascx");

                        ctrl.FirstName = friends[i].FirstName.ToString();
                        ctrl.LastName  = friends[i].LastName.ToString();

                        int friendId = int.Parse(friends[i].UserId.ToString());
                        ctrl.UserId = friendId;
                        // if no profile pic, load default
                        string profilePicture = GetProfilePicture(friendId);
                        ctrl.ImageUrl = profilePicture;

                        ctrl.Description = friends[i].Bio.ToString();
                        ctrl.UserId      = int.Parse(friends[i].UserId.ToString());

                        // bind data to ctrl
                        ctrl.DataBind();

                        // add to panel
                        SearchPanel.Controls.Add(ctrl);
                    }
                    else
                    {
                        FriendCard ctrl = (FriendCard)LoadControl("FriendCard.ascx");

                        ctrl.FirstName = friends[i].FirstName.ToString();
                        ctrl.LastName  = friends[i].LastName.ToString();

                        int friendId = int.Parse(friends[i].UserId.ToString());
                        ctrl.UserId = friendId;

                        // load default pic if there is no profile pic
                        string profilePicture = GetProfilePicture(friendId);
                        ctrl.ImageUrl = profilePicture;


                        // bind data to ctrl
                        ctrl.DataBind();

                        // add to panel
                        SearchPanel.Controls.Add(ctrl);
                    }
                }
            }
            LSearchTitle.Text = "Search results for \"" + searchTerm + "\"";
            LSearchEmpty.Text = friends.Length.ToString();
        }
Example #2
0
        protected void LoadFriends()
        {
            // load other person's friends
            WebRequest  request  = WebRequest.Create(path + "GetFriendsByUserId/" + otherPersonId);
            WebResponse response = request.GetResponse();


            Stream       theDataStream = response.GetResponseStream();
            StreamReader reader        = new StreamReader(theDataStream);
            String       data          = reader.ReadToEnd();

            reader.Close();
            response.Close();

            JavaScriptSerializer js = new JavaScriptSerializer();

            User[] friends = js.Deserialize <User[]>(data);

            for (int i = 0; i < friends.Length; i++)
            {
                if (friends[i].UserId == userId) // if friend is self
                {
                    SelfCard ctrl = (SelfCard)LoadControl("SelfCard.ascx");

                    ctrl.FirstName = friends[i].FirstName.ToString();
                    ctrl.LastName  = friends[i].LastName.ToString();

                    int friendId = int.Parse(friends[i].UserId.ToString());
                    ctrl.UserId = friendId;

                    // load default pic if there is no profile pic
                    string profilePicture = GetProfilePicture(friendId);
                    ctrl.ImageUrl = profilePicture;

                    // bind data to ctrl
                    ctrl.DataBind();

                    // add to panel
                    FriendPanel.Controls.Add(ctrl);
                }
                else
                {
                    // check if friend and load friend card if theyre friends
                    bool areFriends = AreFriends(friends[i].UserId);

                    if (!areFriends) // load non friend card if this person isn't a friend of current user
                    {
                        NonFriendCard ctrl = (NonFriendCard)LoadControl("NonFriendCard.ascx");

                        ctrl.FirstName = friends[i].FirstName.ToString();
                        ctrl.LastName  = friends[i].LastName.ToString();

                        int friendId = int.Parse(friends[i].UserId.ToString());
                        ctrl.UserId = friendId;

                        // if no profile pic, load default
                        string profilePicture = GetProfilePicture(friendId);
                        ctrl.ImageUrl = profilePicture;

                        ctrl.Description = friends[i].Bio.ToString();
                        ctrl.UserId      = int.Parse(friends[i].UserId.ToString());

                        // bind data to ctrl
                        ctrl.DataBind();

                        // add to panel
                        FriendPanel.Controls.Add(ctrl);
                    }
                    else // else if person is also a friend of current user
                    {
                        FriendCard ctrl = (FriendCard)LoadControl("FriendCard.ascx");

                        ctrl.FirstName = friends[i].FirstName.ToString();
                        ctrl.LastName  = friends[i].LastName.ToString();

                        int friendId = int.Parse(friends[i].UserId.ToString());
                        ctrl.UserId = friendId;

                        // load default pic if there is no profile pic
                        string profilePicture = GetProfilePicture(friendId);
                        ctrl.ImageUrl = profilePicture;


                        // bind data to ctrl
                        ctrl.DataBind();

                        // add to panel
                        FriendPanel.Controls.Add(ctrl);
                    }
                }
            }
            // update the badge to show how many
            LFriendsNumber.Text = friends.Length.ToString();
        }
        protected List <int> LoadUsers(string extension, Panel panel)
        {
            WebRequest  request  = WebRequest.Create(path + extension + userId);
            WebResponse response = request.GetResponse();


            Stream       theDataStream = response.GetResponseStream();
            StreamReader reader        = new StreamReader(theDataStream);
            String       data          = reader.ReadToEnd();

            reader.Close();
            response.Close();

            JavaScriptSerializer js = new JavaScriptSerializer();

            User[] friends = js.Deserialize <User[]>(data);

            List <int> UserIds = new List <int>();

            for (int i = 0; i < friends.Length; i++)
            {
                // skip loading the currently logged in user
                if (friends[i].UserId != userId)
                {
                    // skip if this user is already loaded
                    if (!UserIds.Contains(friends[i].UserId))
                    {
                        // check if friend and load friend card if theyre friends
                        bool areFriends = AreFriends(friends[i].UserId);

                        // if not friends, load the not friends card
                        if (!areFriends)
                        {
                            NonFriendCard ctrl = (NonFriendCard)LoadControl("NonFriendCard.ascx");

                            ctrl.FirstName = friends[i].FirstName.ToString();
                            ctrl.LastName  = friends[i].LastName.ToString();

                            int friendId = int.Parse(friends[i].UserId.ToString());
                            ctrl.UserId = friendId;
                            // if no profile pic, load default

                            string profilePicture = GetProfilePicture(friendId);
                            ctrl.ImageUrl = profilePicture;

                            ctrl.Description = friends[i].Bio.ToString();
                            ctrl.UserId      = int.Parse(friends[i].UserId.ToString());

                            // bind data to ctrl
                            ctrl.DataBind();

                            UserIds.Add(friends[i].UserId);
                            // add to panel
                            panel.Controls.Add(ctrl);
                        }
                        else
                        {
                            FriendCard ctrl = (FriendCard)LoadControl("FriendCard.ascx");

                            ctrl.FirstName = friends[i].FirstName.ToString();
                            ctrl.LastName  = friends[i].LastName.ToString();

                            int friendId = int.Parse(friends[i].UserId.ToString());
                            ctrl.UserId = friendId;

                            // load default pic if there is no profile pic
                            string profilePicture = GetProfilePicture(friendId);
                            ctrl.ImageUrl    = profilePicture;
                            ctrl.Description = friends[i].Bio.ToString() + " and you";


                            // bind data to ctrl
                            ctrl.DataBind();

                            UserIds.Add(friends[i].UserId);

                            // add to panel
                            panel.Controls.Add(ctrl);
                        }
                    }
                }
            }
            return(UserIds);
        }