public List <ProfileDisplayClass> loadPassList(string APIKey, string username)
        {
            if (APIKey == this.APIKey)
            {
                User tempUser = new User();
                int  userID   = tempUser.getUserID(username);

                PassedList tempList = new PassedList();
                try
                {
                    string listOfPasses  = tempList.getPasses(userID).List;
                    int[]  passedUserIDs = Array.ConvertAll(listOfPasses.Split('|'), int.Parse);

                    List <ProfileDisplayClass> passedUserProfiles = new List <ProfileDisplayClass>();
                    foreach (int id in passedUserIDs)
                    {
                        ProfileDisplayClass profileDisplay = new ProfileDisplayClass();
                        passedUserProfiles.Add(profileDisplay.retreiveProfileDisplayFromDB(id));
                    }
                    return(passedUserProfiles);
                }
                catch (NullReferenceException)
                {
                    return(null);
                }
            }
            else
            {
                return(new List <ProfileDisplayClass>());
            }
        }
        public int addPasses(string APIKey, string username, string passedProfileUsername)
        {
            if (APIKey == this.APIKey)
            {
                User tempUser     = new User();
                int  userID       = tempUser.getUserID(username);
                int  passedUserID = tempUser.getUserID(passedProfileUsername);

                PassedList tempPasses = new PassedList();
                return(tempPasses.addPassToDB(userID, passedUserID));
            }
            else
            {
                return(0);
            }
        }
        private void loadResults(string city, string state, string gender, string commitment, string haveKids, string wantKids, string occupation)
        {
            string url = "https://localhost:44369/api/DatingService/Search/LoadSearchResults/Member/" + GlobalData.APIKey + "/" + city + "/" + state + "/" + gender + "/" + commitment + "/" + haveKids + "/" + wantKids + "/" + occupation;

            WebRequest  request  = WebRequest.Create(url);
            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();

            MemberSearchResults[]      profileResults     = js.Deserialize <MemberSearchResults[]>(data);
            List <ProfileDisplayClass> profileResultsList = new List <ProfileDisplayClass>();

            foreach (MemberSearchResults result in profileResults)
            {
                User userResult   = new User();
                int  resultUserID = userResult.getUserID(result.Username);


                ProfileDisplayClass profileDisplay = new ProfileDisplayClass();
                profileResultsList.Add(profileDisplay.retreiveProfileDisplayFromDB(resultUserID));
            }

            ArrayList filterPassedProfileResults = new ArrayList();

            User currentUser   = new User();
            int  currentUserID = currentUser.getUserID(Session["Username"].ToString());

            PassedList currentUserPassedList = new PassedList();

            currentUserPassedList = currentUserPassedList.getPasses(currentUserID);

            foreach (ProfileDisplayClass result in profileResultsList)//adds search results that are not currently in the users passed list
            {
                User userResult   = new User();
                int  resultUserID = userResult.getUserID(result.Username);

                if ((currentUserPassedList == null && resultUserID != currentUserID))
                {
                    filterPassedProfileResults.Add(result);
                }
                else if ((currentUserPassedList != null && !currentUserPassedList.List.Contains(resultUserID.ToString())) && (resultUserID != currentUserID))
                {
                    filterPassedProfileResults.Add(result);
                }
            }

            ArrayList   filterUserBlockedProfileResults = new ArrayList();
            BlockedList currentUserBlockedList          = new BlockedList();

            currentUserBlockedList = currentUserBlockedList.getBlocked(currentUserID);

            foreach (ProfileDisplayClass result in filterPassedProfileResults)//adds search results that are not in the users blocked list
            {
                User userResult   = new User();
                int  resultUserID = userResult.getUserID(result.Username);

                if (currentUserBlockedList == null)
                {
                    filterUserBlockedProfileResults.Add(result);
                }
                else if (!currentUserBlockedList.List.Contains(resultUserID.ToString()))
                {
                    filterUserBlockedProfileResults.Add(result);
                }
            }

            ArrayList filterBlockedByProfileResults = new ArrayList();

            foreach (ProfileDisplayClass result in filterUserBlockedProfileResults.ToArray())//adds search results that do not have the current user blocked
            {
                User userResult   = new User();
                int  resultUserID = userResult.getUserID(result.Username);

                BlockedList resultBlockedList = new BlockedList();
                resultBlockedList = resultBlockedList.getBlocked(resultUserID);

                if (resultBlockedList == null)
                {
                    filterBlockedByProfileResults.Add(result);
                }
                else if (!resultBlockedList.List.Contains(resultUserID.ToString()))
                {
                    filterBlockedByProfileResults.Add(result);
                }
            }

            //return filterBlockedByProfileResults;
            List <ProfileDisplayClass> filteredProfiles = filterBlockedByProfileResults.Cast <ProfileDisplayClass>().ToList();

            //Table tblResults = generateResultsTable(filteredProfiles);
            if (filteredProfiles.Count != 0)
            {
                Table tblResults = generateResultsTable(filteredProfiles);
                resultsDiv.Controls.Add(tblResults);
                resultsContainer.Visible = true;
            }
            else
            {
                Label lblNoResults = new Label();
                lblNoResults.ID   = "lblNoResults";
                lblNoResults.Text = "There no profiles that meet your criteria, please search again.";
                resultsDiv.Controls.Add(lblNoResults);
                resultsContainer.Visible = true;
            }
        }
        public bool removeFromPasses(string APIKey, string username, string usernameToRemove)
        {
            if (APIKey == this.APIKey)
            {
                User tempUser       = new User();
                int  userID         = tempUser.getUserID(username);
                int  userIDToRemove = tempUser.getUserID(usernameToRemove);

                PassedList tempList      = new PassedList();
                string     passesList    = tempList.getPasses(userID).List;
                int[]      passedUserIDs = Array.ConvertAll(passesList.Split('|'), int.Parse);

                List <int> passes = new List <int>(passedUserIDs);
                string     newPassesList;
                if (passes.Count == 1)
                {
                    //newPassesList = null;

                    DBConnect  objDB  = new DBConnect();
                    SqlCommand objCmd = new SqlCommand();
                    objCmd.CommandType = CommandType.StoredProcedure;
                    objCmd.CommandText = "TP_RemovePasses";
                    objCmd.Parameters.AddWithValue("@passedBy", userID);
                    int result = objDB.DoUpdateUsingCmdObj(objCmd);
                    if (result == 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    int index = passes.IndexOf(userIDToRemove);
                    passes.RemoveAt(index);
                    newPassesList = string.Join('|', passes) + "|";

                    DBConnect  objDB  = new DBConnect();
                    SqlCommand objCmd = new SqlCommand();
                    objCmd.CommandType = CommandType.StoredProcedure;
                    objCmd.CommandText = "TP_ModifyPasses";
                    objCmd.Parameters.AddWithValue("@passed", newPassesList);
                    objCmd.Parameters.AddWithValue("@passedBy", userID);
                    int result = objDB.DoUpdateUsingCmdObj(objCmd);

                    if (result == 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }