private void BtnSubmit_Click(object sender, RoutedEventArgs e) { var member = new Member { firstName = txtFirstName.Text, lastName = txtLastName.Text, password = txtPassword.Password.ToString(), address = txtAddress.Text, avatar = txtAvatar.Text, birthday = txtBirthday.Text, email = txtEmail.Text, gender = Int32.Parse(txtGender.Text), introduction = txtIntroduction.Text, phone = txtPhone.Text }; ////Debug.WriteLine(JsonConvert.SerializeObject(member)); //Debug.WriteLine(JsonConvert.SerializeObject(member)); //var httpClient = new HttpClient(); ////httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + token); //HttpContent content = new StringContent(JsonConvert.SerializeObject(member), Encoding.UTF8, // "application/json"); //Task<HttpResponseMessage> httpRequestMessage = httpClient.PostAsync(ApiUrl, content); //String responseContent = httpClient.PostAsync(ApiUrl, content).Result.Content.ReadAsStringAsync().Result; //Debug.WriteLine("Response: " + responseContent); //Member resMember = JsonConvert.DeserializeObject<Member>(responseContent); //JObject resJObject = JObject.Parse(responseContent); //Debug.WriteLine(resMember.email); //Debug.WriteLine(resJObject["email"]); MemberServiceImp memberServiceImp = new MemberServiceImp(); memberServiceImp.FormRegister(member, ApiUrl); }
private void ButtonBase_JsonOnClick(object sender, RoutedEventArgs e) { var user = new User { firstName = FirstName.Text, lastName = LastName.Text, avatar = AvatarUrl.Text, phone = Phone.Text, address = Address.Text, introduction = Introduction.Text, gender = Int32.Parse(Gender.Text), birthday = Birthday.Text, email = Email.Text, password = Password.Password }; MemberServiceImp memberServiceImp = new MemberServiceImp(); memberServiceImp.FormRegister(user, api); }
private void BtnSubmit_Click(object sender, RoutedEventArgs e) { var member = new Member { firstName = txtFirstName.Text, lastName = txtLastName.Text, password = txtPassword.Password, address = txtAddress.Text, avatar = txtAvatar.Text, birthday = txtBirthday.Text, email = txtEmail.Text, gender = Int32.Parse(txtGender.Text), introduction = txtIntroduction.Text, phone = txtPhone.Text }; Dictionary <String, String> errors = member.Validate(); if (errors.Count == 0) { memberServiceImp.FormRegister(member, ApiUrl.URL_REGISTER); } else { if (errors.ContainsKey("firstName")) { FirstNameMessage.Text = errors["firstName"]; FirstNameMessage.Visibility = Visibility.Visible; } else { FirstNameMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("lastName")) { LastNameMessage.Text = errors["lastName"]; LastNameMessage.Visibility = Visibility.Visible; } else { LastNameMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("avatar")) { AvatarMessage.Text = errors["avatar"]; AvatarMessage.Visibility = Visibility.Visible; } else { AvatarMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("phone")) { PhoneMessage.Text = errors["phone"]; PhoneMessage.Visibility = Visibility.Visible; } else { PhoneMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("address")) { AddressMessage.Text = errors["address"]; AddressMessage.Visibility = Visibility.Visible; } else { AddressMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("introduction")) { IntroductionMessage.Text = errors["introduction"]; IntroductionMessage.Visibility = Visibility.Visible; } else { IntroductionMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("gender")) { GenderMessage.Text = errors["gender"]; GenderMessage.Visibility = Visibility.Visible; } else { GenderMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("birthday")) { BirthdayMessage.Text = errors["birthday"]; BirthdayMessage.Visibility = Visibility.Visible; } else { BirthdayMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("email")) { EmailMessage.Text = errors["email"]; EmailMessage.Visibility = Visibility.Visible; } else { EmailMessage.Visibility = Visibility.Collapsed; } if (errors.ContainsKey("password")) { PasswordMessage.Text = errors["password"]; PasswordMessage.Visibility = Visibility.Visible; } else { PasswordMessage.Visibility = Visibility.Collapsed; } if (txtPassword.Password != txtConfirmPassword.Password) { ConfirmPasswordMessage.Text = "Not match!"; ConfirmPasswordMessage.Visibility = Visibility.Visible; } else { ConfirmPasswordMessage.Visibility = Visibility.Collapsed; } } ////Debug.WriteLine(JsonConvert.SerializeObject(member)); //Debug.WriteLine(JsonConvert.SerializeObject(member)); //var httpClient = new HttpClient(); ////httpClient.DefaultRequestHeaders.Add("Authorization", "Basic " + token); //HttpContent content = new StringContent(JsonConvert.SerializeObject(member), Encoding.UTF8, // "application/json"); //Task<HttpResponseMessage> httpRequestMessage = httpClient.PostAsync(ApiUrl, content); //String responseContent = httpClient.PostAsync(ApiUrl, content).Result.Content.ReadAsStringAsync().Result; //Debug.WriteLine("Response: " + responseContent); //Member resMember = JsonConvert.DeserializeObject<Member>(responseContent); //JObject resJObject = JObject.Parse(responseContent); //Debug.WriteLine(resMember.email); //Debug.WriteLine(resJObject["email"]); }