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 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); }