Пример #1
0
        private void loadPrivacySettings(string username)
        {
            string url = "https://localhost:44369/api/DatingService/Profiles/LoadPrivacySettings/" + GlobalData.APIKey + "/" + username;

            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();
            UserPrivacySettings  privacyObj = js.Deserialize <UserPrivacySettings>(data);

            ddPrivacyProfilePic.SelectedValue  = privacyObj.ProfilePic;
            ddPrivacyFirstName.SelectedValue   = privacyObj.FirstName;
            ddPrivacyLastName.SelectedValue    = privacyObj.LastName;
            ddPrivacyTitle.SelectedValue       = privacyObj.Title;
            ddPrivacyGender.SelectedValue      = privacyObj.Gender;
            ddPrivacyAge.SelectedValue         = privacyObj.Age;
            ddPrivacyHeight.SelectedValue      = privacyObj.Height;
            ddPrivacyWeight.SelectedValue      = privacyObj.Weight;
            ddPrivacyOccupation.SelectedValue  = privacyObj.Occupation;
            ddPrivacyCommitment.SelectedValue  = privacyObj.Commitment;
            ddPrivacyHaveKids.SelectedValue    = privacyObj.HaveKids;
            ddPrivacyWantKids.SelectedValue    = privacyObj.WantKids;
            ddPrivacyInterests.SelectedValue   = privacyObj.Interests;
            ddPrivacyDescription.SelectedValue = privacyObj.Description;
        }
Пример #2
0
        private void modifyPrivacy()
        {
            UserPrivacySettings settings = new UserPrivacySettings();

            settings.ProfilePic  = ddPrivacyProfilePic.SelectedValue;
            settings.FirstName   = ddPrivacyFirstName.SelectedValue;
            settings.LastName    = ddPrivacyLastName.SelectedValue;
            settings.Title       = ddPrivacyTitle.SelectedValue;
            settings.Age         = ddPrivacyAge.SelectedValue;
            settings.Height      = ddPrivacyHeight.SelectedValue;
            settings.Weight      = ddPrivacyWeight.SelectedValue;
            settings.Occupation  = ddPrivacyOccupation.SelectedValue;
            settings.Commitment  = ddPrivacyCommitment.SelectedValue;
            settings.HaveKids    = ddPrivacyHaveKids.SelectedValue;
            settings.WantKids    = ddPrivacyWantKids.SelectedValue;
            settings.Interests   = ddPrivacyInterests.SelectedValue;
            settings.Description = ddPrivacyDescription.SelectedValue;
            settings.Gender      = ddPrivacyGender.SelectedValue;

            JavaScriptSerializer js = new JavaScriptSerializer();
            string jsonPrivacyObj   = js.Serialize(settings);

            try
            {
                string     url     = "https://localhost:44369/api/DatingService/Profiles/ModifyPrivacySettings/" + GlobalData.APIKey + "/" + Session["Username"].ToString();
                WebRequest request = WebRequest.Create(url);
                request.Method        = "POST";
                request.ContentLength = jsonPrivacyObj.Length;
                request.ContentType   = "application/json";

                //Write the JSON data to the Web Request
                StreamWriter writer = new StreamWriter(request.GetRequestStream());
                writer.Write(jsonPrivacyObj);
                writer.Flush();
                writer.Close();

                //Read the data from the Web Response
                WebResponse  response      = request.GetResponse();
                Stream       theDataStream = response.GetResponseStream();
                StreamReader reader        = new StreamReader(theDataStream);
                string       data          = reader.ReadToEnd();
                reader.Close();
                response.Close();

                if (data != "true")
                {
                    lblErrorMsg.Text   += "*A problem occured while updating your privacy settings. <br />";
                    lblErrorMsg.Visible = true;
                }
            }
            catch (Exception ex)
            {
                lblErrorMsg.Text   += "*Error: " + ex.Message + "<br />";
                lblErrorMsg.Visible = true;
            }
        }
        public UserPrivacySettings loadPrivacySettings(string APIKey, string username)
        {
            if (APIKey == this.APIKey)
            {
                User tempUser = new User();
                int  userID   = tempUser.getUserID(username);

                UserPrivacySettings privacySettings = new UserPrivacySettings();
                return(privacySettings.retrievePrivacySettings(userID));
            }
            else
            {
                return(new UserPrivacySettings());
            }
        }
 public bool modifyPrivacySettings(string APIKey, [FromBody] UserPrivacySettings settings, string username)
 {
     if (APIKey == this.APIKey)
     {
         if (settings != null)
         {
             User tempUser = new User();
             int  userID   = tempUser.getUserID(username);
             UserPrivacySettings tempSettings = new UserPrivacySettings();
             return(tempSettings.modifyPrivacySettings(settings, userID));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
        protected void btnSaveProfile_Click(object sender, EventArgs e)
        {
            lblErrorMsg.Text    = string.Empty;
            lblErrorMsg.Visible = false;

            if (validateFields())
            {
                DBConnect           objDB = new DBConnect();
                SqlCommand          objCmd = new SqlCommand();
                User                tempUser = new User();
                UserProfile         profile = new UserProfile();
                UserPrivacySettings privacySettings = new UserPrivacySettings();
                string              defaultPrivacySetting = "Visible";
                int    result = 0, imageSize;
                string fileExt, imageName;
                string haveKids = drpHaveKids.SelectedValue;
                string wantKids = drpWantKids.SelectedValue;
                string commitment = drpCommitment.SelectedValue;
                string gender = drpGender.SelectedValue;
                int    userID = tempUser.getUserID(Session["Username"].ToString());
                string height = txtHeightFeet.Text + "|" + txtHeightIn.Text;

                try
                {
                    if (fileProfilePic.HasFile)
                    {
                        imageSize = fileProfilePic.PostedFile.ContentLength;
                        byte[] imageData = new byte[imageSize];

                        fileProfilePic.PostedFile.InputStream.Read(imageData, 0, imageSize);
                        imageName = fileProfilePic.PostedFile.FileName;

                        fileExt = imageName.Substring(imageName.LastIndexOf("."));
                        fileExt = fileExt.ToLower();

                        //string imageDataAsString = System.Text.Encoding.Default.GetString(imageData);

                        if (fileExt == ".jpg")
                        {
                            result = profile.addUserProfileToDB(txtPhone.Text, imageData, txtOccupation.Text, int.Parse(txtAge.Text), height, int.Parse(txtWeight.Text),
                                                                txtTitle.Text, commitment, haveKids, wantKids, txtInterests.Text, txtDescription.Text, userID, gender);
                            result += privacySettings.addUserSettingsToDB(defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting,
                                                                          defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting,
                                                                          defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, userID);
                            if (result == 2)
                            {
                                //User profile created successfully
                                Session.Add("RequestedProfile", Session["Username"].ToString());
                                Response.Redirect("Profile.aspx"); //redirect to member only search page or profile page?
                            }
                        }
                        else
                        {
                            lblErrorMsg.Text   += "*Only jpg file types supported. <br />";
                            lblErrorMsg.Visible = true;
                        }
                    }
                    else //if no profile pic
                    {
                        byte[] noImage = null;
                        //inserts 'null' for the imageData field
                        result = profile.addUserProfileToDB(txtPhone.Text, noImage, txtOccupation.Text, int.Parse(txtAge.Text), height, int.Parse(txtWeight.Text),
                                                            txtTitle.Text, commitment, haveKids, wantKids, txtInterests.Text, txtDescription.Text, userID, gender);
                        result += privacySettings.addUserSettingsToDB(defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting,
                                                                      defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting,
                                                                      defaultPrivacySetting, defaultPrivacySetting, defaultPrivacySetting, userID);
                        if (result == 2)
                        {
                            //User profile created successfully
                            Session.Add("RequestedProfile", Session["Username"].ToString());
                            Response.Redirect("Profile.aspx"); //redirect to member only search page or profile page?
                        }
                    }
                }
                catch (Exception ex)
                {
                    lblErrorMsg.Text   += "Error occurred: [" + ex.Message + "] cmd=" + result;
                    lblErrorMsg.Visible = true;
                }
            }
        }