Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.33/5 (9 votes)
See more:
I have made socialportal. User 1 login in and search the name the user which alreay registerd in website and send request to him/her. Friend request is sent. The problem is that when user to which request is send is login in userfriendcontrol not display userfriendcontrol is actually accept/deny conrol that user accept/deny user 1 request

my database tables are here
table name User
 ID            int
Email         varchar(500)
Password       varchar(500)
Name            varchar(500)
Country        varchar(500)
LastLogin            datetime
RegisterDate         datetime
Description          Varchar(500)
ImageName           varchar(500)
table name Friends
Id             int
MyId              int
FriendId        int
Message              text
FriendStatus bit // this is not updated in code
FriendShipDate  datetime
ImageName  varchar(500)



two page UserDetails.cs and UserFriendRequest control.ascx


Userdetails.cs
C#
 DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GetUserDetails(int.Parse(Request.QueryString["Id"].ToString()));
            if (!object.Equals(Session["UserId"], null))
            {
                if (object.Equals(Session["UserId"], Request.QueryString["Id"]))
                {
                    UserFriendRequest.Visible = true;
                }
                else
                {
                    UserFriendRequest.Visible = false;
                }
            }
        }
    }
    public void GetUserDetails(int id)
    {
        string getUserDetail = "Select ID,Email,Name,Country,Convert(varchar (20), RegisterDate, 106) RegisterDate,Convert(varchar (20), LastLogin, 106) LastLogin ,Description,ImageName FROM [User] where Id='" + id + "'";
        dt = dbClass.ConnectDataBaseReturnDT(getUserDetail);
        if (dt.Rows.Count > 0)
        {
            UserImage.ImageUrl = "~/UserImage/" + dt.Rows[0]["ImageName"].ToString();
            lblCreated.Text = dt.Rows[0]["RegisterDate"].ToString();
            LabelLastLogin.Text = dt.Rows[0]["LastLogin"].ToString();
            lblCreated.Text = dt.Rows[0]["RegisterDate"].ToString();
            LabelAboutMe.Text = dt.Rows[0]["Description"].ToString();
        }
    }
    protected void AddToFriend_Click(object sender, EventArgs e)
    {
        if (!object.Equals(Session["UserId"], null))
        {
            if (Object.Equals(Session["UserId"], Request.QueryString["Id"]))
            {
                lblError.Text = "Your own profile";
                lblError.Visible = true;
            }
            else
            {
                string chkfriendRequest = "SELECT * FROM Friends WHERE (MyId='" + Session["UserId"].ToString() + "' and FriendId='" + Request.QueryString["Id"].ToString() + "') OR (MyId='" + Request.QueryString["Id"].ToString() + "' and FriendId='" + Session["UserId"].ToString() + "')";
                DataTable dt1 = new DataTable();
                dt1 = dbClass.ConnectDataBaseReturnDT(chkfriendRequest);
                if (dt1.Rows.Count > 0)
                {
         problem area/*           if (dt1.Rows[0]["FriendStatus"].ToString() == "1")
                    {
                        lblError.Text = "Already in friend list";
                        lblError.Visible = true;
                    }
                    if (dt1.Rows[0]["FriendStatus"].ToString() == "0")
                    {
                        lblError.Text = "Friend Request Pending";
                        lblError.Visible = true;
                    }
                    if (dt1.Rows[0]["FriendStatus"].ToString() == "2")
                    {
                        lblError.Text = "Friend Request deny";
                        lblError.Visible = true;      */ problem area
                    }
                }
                else
                {
                    string friendRequest = "Insert INTO Friends (MyId,FriendId) VALUES('" + Session["UserId"].ToString() + "','" + Request.QueryString["Id"].ToString() + "')";
                    dbClass.ConnectDataBaseToInsert(friendRequest);
                    lblError.Text = "Friend Request Send";
                    lblError.Visible = true;
                }
            }
        }
        else
        {
            Response.Redirect("~/Login.aspx");
        }
    }
    protected void ButtonPostScrap_Click(object sender, EventArgs e)
    {
        if (!object.Equals(Session["UserId"], null))
        {
            string postScrap = "Insert INTO Scrap (FromId,ToId,Message) VALUES('" + Session["UserId"].ToString() + "','" + Request.QueryString["Id"].ToString() + "','" + TextBoxScrap.Text + "')";
            dbClass.ConnectDataBaseToInsert(postScrap);
            Response.Redirect("Userdetails.aspx?Id=" + Request.QueryString["Id"].ToString());
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
UserFriendRequest.ascx.cs


DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GetUserFriendsRequest(int.Parse(Request.QueryString["Id"].ToString()));
        }
    } 
    public void GetUserFriendsRequest(int Id)
    {
        string getFriendRequestQuery = "Select * FROM [User] where Id IN (SELECT MyId as Id FROM Friends WHERE FriendId='" + Id + "' AND FriendStatus=0) ";
        dt = dbClass.ConnectDataBaseReturnDT(getFriendRequestQuery);
        if (dt.Rows.Count > 0)
        {
            FreindRequestList.DataSource = dt;
            FreindRequestList.DataBind();
        }
    }
    public string getHREF(object sURL)
    {
        DataRowView dRView = (DataRowView)sURL;
        string Id = dRView["Id"].ToString();
        return ResolveUrl("~/Userdetails.aspx?Id=" + Id);
    }
    public string getSRC(object imgSRC)
    {
        DataRowView dRView = (DataRowView)imgSRC;
        string ImageName = dRView["ImageName"].ToString();
        if (ImageName == "NoImage")
        {
            return ResolveUrl(@"~/UserImage/missing.jpg");
        }
        else
        {
            return ResolveUrl("~/UserImage/" + dRView["ImageName"].ToString());
        }
    }
    protected void FreindRequestList_ItemCommand(object source, DataListCommandEventArgs e)
    {
     not display on userdetails page problem area/*   if (!object.Equals(Session["UserId"], null))
        {
            if (e.CommandName == "Accept")
            {
                string SenderFriendId = ((HtmlInputHidden)e.Item.FindControl("hiddenId")).Value;
                string MyID = Session["UserId"].ToString();
                string AcceptFriendQuery = "Update Friends set FriendStatus=1 where MyId='" + SenderFriendId + "' AND FriendId='" + MyID + "'";
                dbClass.ConnectDataBaseToInsert(AcceptFriendQuery);
                Response.Redirect("Userdetails.aspx?Id=" + Request.QueryString["Id"].ToString());
            }
            if (e.CommandName == "Deny")
            {
                string SenderFriendId = ((HtmlInputHidden)e.Item.FindControl("hiddenId")).Value;
                string MyID = Session["UserId"].ToString();
                string AcceptFriendQuery = "Update Friends set FriendStatus=2 where MyId='" + SenderFriendId + "' AND FriendId='" + MyID + "'";
                dbClass.ConnectDataBaseToInsert(AcceptFriendQuery);
                Response.Redirect("Userdetails.aspx?Id=" + Request.QueryString["Id"].ToString());
            }
        }
    }*/problem area  not update the FriendStatus
Posted
Updated 17-Apr-11 23:44pm
v3
Comments
Manfred Rudolf Bihy 18-Apr-11 3:13am    
Edit: Added code tags.
Manfred Rudolf Bihy 18-Apr-11 3:14am    
"Code is working" and now what? If it is working why would anybody want to check anything. Please reformulate your question as it is not understandable what you want from us.
walterhevedeich 18-Apr-11 5:44am    
Changed textspeak in the title.
BobJanova 18-Apr-11 5:59am    
Not trying to be funny but ... please write the description of your problem in English.
Neerajan Lamsal 2-May-11 8:39am    
zip the project to me i will find the best answer for you..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900