protected void gv_Users_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { Guid theOtherId = (Guid)(gv_Users.DataKeys[e.NewSelectedIndex].Values[0]); MembershipUser CurrentUser = Membership.GetUser(); if (CurrentUser == null) { Response.Redirect($"~/Pages/Common/MainLogin.aspx"); } Guid UserId = (Guid)((Membership.GetUser()).ProviderUserKey); bool checkSent = ConnectionBLL.CheckFromTo(UserId, theOtherId); bool checkReceived = ConnectionBLL.CheckFromTo(theOtherId, UserId); if (checkSent) { lbl_requestSent.Text = $"a connection Request has been already Sent "; lbl_requestSent.Visible = true; } else if (checkReceived) { ConnectionBLL.ModifyConnectionAccepted(theOtherId, UserId); string name = gv_Users.DataKeys[e.NewSelectedIndex].Values[1].ToString(); lbl_requestSent.Text = $"{name} has sent you a Request you are now connected "; lbl_requestSent.Visible = true; } else { ConnectionBLL.AddnewConnection(UserId, theOtherId); string name = gv_Users.DataKeys[e.NewSelectedIndex].Values[1].ToString(); lbl_requestSent.Text = $"connection Request Sent To {name}"; lbl_requestSent.Visible = true; } ConnectionBLL.DeleteReplicate(); Response.Redirect("~/Pages/User/Connections.aspx"); }