public bool checkIfUsersLikeEachOther(string username1, string username2) { User tempUser = new User(); int userID1 = tempUser.getUserID(username1); int userID2 = tempUser.getUserID(username2); bool check = true; LikedList tempList = new LikedList(); try { string likedProfiles1 = tempList.getLikes(userID1).List; int[] likedUserIDs1 = Array.ConvertAll(likedProfiles1.Split('|'), int.Parse); string likedProfiles2 = tempList.getLikes(userID2).List; int[] likedUserIDs2 = Array.ConvertAll(likedProfiles2.Split('|'), int.Parse); if (!likedUserIDs1.Contains(userID2)) { check = false; } if (!likedUserIDs2.Contains(userID1)) { check = false; } return(check); } catch (NullReferenceException) { return(false); } }
public LikedList getLikes(int userID) { DBConnect objDB = new DBConnect(); SqlCommand objCmd = new SqlCommand(); objCmd.CommandType = CommandType.StoredProcedure; objCmd.CommandText = "TP_GetLikes"; objCmd.Parameters.AddWithValue("@likedBy", userID); DataSet likesDS = objDB.GetDataSetUsingCmdObj(objCmd); LikedList likesList = new LikedList(); if (likesDS.Tables[0].Rows.Count > 0) { if (objDB.GetField("Liked", 0) == DBNull.Value) { return(null); } else { likesList.List = likesDS.Tables[0].Rows[0]["Liked"].ToString().TrimEnd('|'); return(likesList); } } else { return(null); } }
public bool checkIfUserLikesOtherUser(string username1, string username2) { User tempUser = new User(); int userID1 = tempUser.getUserID(username1); int userID2 = tempUser.getUserID(username2); LikedList tempList = new LikedList(); try { string likedProfiles1 = tempList.getLikes(userID1).List; int[] likedUserIDs1 = Array.ConvertAll(likedProfiles1.Split('|'), int.Parse); if (likedUserIDs1.Contains(userID2)) { return(true); } else { return(false); } } catch (NullReferenceException) { return(false); } }
public int addLikeToDB(int userID, int likedUserID) { int result = 0; DBConnect objDB = new DBConnect(); SqlCommand objCmd = new SqlCommand(); objCmd.CommandType = CommandType.StoredProcedure; LikedList tempLikes = new LikedList(); string likeList; User tempUser = new User(); //int likedUserID = tempUser.getUserID(likedProfile); try { likeList = tempLikes.getLikes(userID).List; likeList += "|" + likedUserID + "|"; objCmd.CommandText = "TP_ModifyLikes"; objCmd.Parameters.AddWithValue("@liked", likeList); objCmd.Parameters.AddWithValue("@likedBy", userID); result = objDB.DoUpdateUsingCmdObj(objCmd); } catch (NullReferenceException) { //list of likes is empty, so add the first like likeList = likedUserID + "|"; objCmd.CommandText = "TP_AddLike"; objCmd.Parameters.AddWithValue("@liked", likeList); objCmd.Parameters.AddWithValue("@likedBy", userID); result = objDB.DoUpdateUsingCmdObj(objCmd); } return(result); }