public static async Task PopulateProfile(ProfileViewModel profile) { HttpResponseMessage response = await client.GetAsync("https://www.myhealth.va.gov/mhv-portal-web/mhv.portal?_nfpb=true&_pageLabel=profiles&_nfls=false"); string page = await response.Content.ReadAsStringAsync(); HtmlDocument document = new HtmlDocument(); document.LoadHtml(page); profile.Token = ExtractToken(page); profile.FirstName = document.GetElementbyId("firstName").GetAttributeValue("value", string.Empty); profile.MiddleName = document.GetElementbyId("middleName").GetAttributeValue("value", string.Empty); profile.LastName = document.GetElementbyId("lastName").GetAttributeValue("value", string.Empty); profile.Alias = document.GetElementbyId("userAlias").GetAttributeValue("value", string.Empty); profile.Gender = document.GetElementbyId("gender").GetAttributeValue("value", string.Empty); profile.BirthMonth = document.GetElementbyId("monthSelect").GetAttributeValue("value", string.Empty); profile.BirthDate = document.GetElementbyId("daySelect").GetAttributeValue("value", string.Empty); profile.BirthYear = document.GetElementbyId("yearSelect").GetAttributeValue("value", string.Empty); profile.Occupation = document.GetElementbyId("currentOccupation").GetAttributeValue("value", string.Empty); profile.MaritalStatus = document.GetElementbyId("maritalStatus").ChildNodes.Single(c => c.Attributes.Contains("selected")).NextSibling.InnerText; profile.ContactMethod = document.GetElementbyId("contactMethod").ChildNodes.Single(c => c.Attributes.Contains("selected")).NextSibling.InnerText; profile.Email = document.GetElementbyId("primaryEmail").GetAttributeValue("value", string.Empty); profile.MobilePhone = document.GetElementbyId("mobilePhone").GetAttributeValue("value", string.Empty); profile.HomePhone = document.GetElementbyId("homePhone").GetAttributeValue("value", string.Empty); profile.WorkPhone = document.GetElementbyId("workPhone").GetAttributeValue("value", string.Empty); profile.Fax = document.GetElementbyId("fax").GetAttributeValue("value", string.Empty); profile.Pager = document.GetElementbyId("pager").GetAttributeValue("value", string.Empty); profile.AddressLine1 = document.GetElementbyId("street1").GetAttributeValue("value", string.Empty); profile.AddressLine2 = document.GetElementbyId("street2").GetAttributeValue("value", string.Empty); profile.City = document.GetElementbyId("city").GetAttributeValue("value", string.Empty); profile.State = document.GetElementbyId("state").ChildNodes.Single(c => c.Attributes.Contains("selected")).NextSibling.InnerText; profile.ZipCode = document.GetElementbyId("postalCode").GetAttributeValue("value", string.Empty); profile.Province = document.GetElementbyId("province").GetAttributeValue("value", string.Empty); profile.Country = document.GetElementbyId("country").ChildNodes.Single(c => c.Attributes.Contains("selected")).NextSibling.InnerText; profile.Question1 = document.GetElementbyId("hintQuestion1").ChildNodes.Single(c => c.Attributes.Contains("selected")).NextSibling.InnerText; profile.Question2 = document.GetElementbyId("hintQuestion2").ChildNodes.Single(c => c.Attributes.Contains("selected")).NextSibling.InnerText; profile.Answer1 = document.GetElementbyId("hintAnswer1").GetAttributeValue("value", string.Empty); profile.Answer2 = document.GetElementbyId("hintAnswer2").GetAttributeValue("value", string.Empty); profile.PrivacyAccepted = document.DocumentNode.Descendants().Single(d => string.Equals(d.GetAttributeValue("name", string.Empty), privacyName, StringComparison.CurrentCultureIgnoreCase)).GetAttributeValue("value", false); profile.TermsAccepted = document.DocumentNode.Descendants().Single(d => string.Equals(d.GetAttributeValue("name", string.Empty), termsName, StringComparison.CurrentCultureIgnoreCase)).GetAttributeValue("value", false); profile.IsVAPatient = document.GetElementbyId("vaPatient").GetAttributeValue("value", true); profile.IsVeteranAdvocate = document.GetElementbyId("patientAdvocate").Attributes.Contains("checked"); profile.IsVeteran = document.GetElementbyId("veteran").Attributes.Contains("checked"); profile.IsVAEmployee = document.GetElementbyId("vaEmployee").Attributes.Contains("checked"); profile.IsHealthProvider = document.GetElementbyId("healthCareProvider").Attributes.Contains("checked"); profile.IsOther = document.GetElementbyId("isOther").Attributes.Contains("checked"); profile.BloodType = document.GetElementbyId("bloodType").ChildNodes.Single(c => c.Attributes.Contains("selected")).NextSibling.InnerText; profile.IsOrganDonor = document.GetElementbyId("organDonor").Attributes.Contains("checked"); }
public static async Task SaveProfile(ProfileViewModel profile) { List<KeyValuePair<string, string>> postParamters = new List<KeyValuePair<string, string>>(); postParamters.Add(new KeyValuePair<string, string>(profileTokenName, profile.Token)); postParamters.Add(new KeyValuePair<string, string>(firstNameName, profile.FirstName)); postParamters.Add(new KeyValuePair<string, string>(middleNameName, profile.MiddleName)); postParamters.Add(new KeyValuePair<string, string>(lastNameName, profile.LastName)); postParamters.Add(new KeyValuePair<string, string>(aliasName, profile.Alias)); postParamters.Add(new KeyValuePair<string, string>(genderName, profile.Gender)); postParamters.Add(new KeyValuePair<string, string>(birthMonthName, profile.BirthMonth)); postParamters.Add(new KeyValuePair<string, string>(birthDateName, profile.BirthDate)); postParamters.Add(new KeyValuePair<string, string>(birthYearName, profile.BirthYear)); postParamters.Add(new KeyValuePair<string, string>(maritalStatusName, profile.MaritalStatus)); postParamters.Add(new KeyValuePair<string, string>(occupationName, profile.Occupation)); postParamters.Add(new KeyValuePair<string, string>(contactMethodName, profile.ContactMethod)); postParamters.Add(new KeyValuePair<string, string>(emailName, profile.Email)); postParamters.Add(new KeyValuePair<string, string>(mobilePhoneName, profile.MobilePhone)); postParamters.Add(new KeyValuePair<string, string>(homePhoneName, profile.HomePhone)); postParamters.Add(new KeyValuePair<string, string>(workPhoneName, profile.WorkPhone)); postParamters.Add(new KeyValuePair<string, string>(faxName, profile.Fax)); postParamters.Add(new KeyValuePair<string, string>(pagerName, profile.Pager)); postParamters.Add(new KeyValuePair<string, string>(address1Name, profile.AddressLine1)); postParamters.Add(new KeyValuePair<string, string>(address2Name, profile.AddressLine2)); postParamters.Add(new KeyValuePair<string, string>(cityName, profile.City)); postParamters.Add(new KeyValuePair<string, string>(stateName, profile.State)); postParamters.Add(new KeyValuePair<string, string>(zipName, profile.ZipCode)); postParamters.Add(new KeyValuePair<string, string>(provinceName, profile.Province)); postParamters.Add(new KeyValuePair<string, string>(countryName, profile.Country)); postParamters.Add(new KeyValuePair<string, string>(question1Name, profile.Question1)); postParamters.Add(new KeyValuePair<string, string>(question2Name, profile.Question2)); postParamters.Add(new KeyValuePair<string, string>(answer1Name, profile.Answer1)); postParamters.Add(new KeyValuePair<string, string>(answer2Name, profile.Answer2)); postParamters.Add(new KeyValuePair<string, string>(privacyName, profile.PrivacyAccepted.ToString().ToLower())); postParamters.Add(new KeyValuePair<string, string>(termsName, profile.TermsAccepted.ToString().ToLower())); postParamters.Add(new KeyValuePair<string, string>(bloodTypeName, profile.BloodType)); if (profile.IsVAPatient) { postParamters.Add(new KeyValuePair<string, string>(isVAPatientName, "on")); } if (profile.IsVeteranAdvocate) { postParamters.Add(new KeyValuePair<string, string>(isVeteranAdvocateName, "on")); } if (profile.IsVeteran) { postParamters.Add(new KeyValuePair<string, string>(isVeteranName, "on")); } if (profile.IsVAEmployee) { postParamters.Add(new KeyValuePair<string, string>(isVAEmployeeName, "on")); } if (profile.IsHealthProvider) { postParamters.Add(new KeyValuePair<string, string>(isHealthProviderName, "on")); } if (profile.IsOther) { postParamters.Add(new KeyValuePair<string, string>(isOtherName, "on")); } if (profile.IsOrganDonor) { postParamters.Add(new KeyValuePair<string, string>(isOrganDonorName, "on")); } HttpContent content = new FormUrlEncodedContent(postParamters); HttpResponseMessage response = await client.PostAsync("https://www.myhealth.va.gov:443/mhv-portal-web/mhv.portal?_nfpb=true&_windowLabel=manageUserProfile_profiles&manageUserProfile_profiles_actionOverride=%2Fgov%2Fva%2Fmed%2Fmhv%2Fusermgmt%2Fportlet%2FsaveAction&_pageLabel=profilesHome", content); string page = await response.Content.ReadAsStringAsync(); }