private async void add_Tapped(object sender, EventArgs e) { string serialNumberText = "", deviceNumberText = ""; if (checkBox.IsChecked == true) { var isValid = _context.Validate(); if (isValid) { if (password.Text.Equals(confirmPassword.Text)) { if (!string.IsNullOrEmpty(snText.Text) || !string.IsNullOrEmpty(deviceText.Text)) { if (!string.IsNullOrEmpty(snText.Text)) { ValidateUserSN(snText.Text); } if (!string.IsNullOrEmpty(this.deviceText.Text) && string.IsNullOrEmpty(this.snText.Text)) { snResult = true; } if (snResult) { if (NetworkCheck.IsInternet()) { if (!string.IsNullOrEmpty(this.snText.Text)) { serialNumberText = this.snText.Text; } if (!string.IsNullOrEmpty(this.deviceText.Text)) { deviceNumberText = this.deviceText.Text; } using (var client = new HttpClient()) { if (!string.IsNullOrEmpty(userPhotoImageSN)) { userPhotoImageSN = userPhotoImageSN + extension; } var postData = new UserRegister { sex = this.sex, birthday = this.birthday, tall = this.tall, weight = this.weight, age = this.age, userName = this.userName.Text, email = this.email.Text, userPWD = this.password.Text, serialNumber = serialNumberText, deviceNumber = deviceNumberText, userPhotoImage = userPhotoImageSN }; //create the request content and define Json var json = JsonConvert.SerializeObject(postData); var content = new StringContent(json, Encoding.UTF8, "application/json"); // send a POST request var uri = app.url + "/AR_admin/addUser"; var result = await client.PostAsync(uri, content); if (result.IsSuccessStatusCode) { var resultString = await result.Content.ReadAsStringAsync(); var post = JsonConvert.DeserializeObject <Result>(resultString); if (post != null && post.result != null && post.result != "" && post.result == "0") { if (Xamarin.Forms.Application.Current.Properties.ContainsKey("email") != false) { Xamarin.Forms.Application.Current.Properties["email"] = email.Text; } else { Xamarin.Forms.Application.Current.Properties.Add("email", email.Text); } await Xamarin.Forms.Application.Current.SavePropertiesAsync(); await DisplayAlert("訊息", "註冊帳號成功!", "OK"); await Navigation.PushAsync(new MyProfile(), true); Navigation.RemovePage(this); } else { await DisplayAlert("訊息", "註冊帳號失敗!請稍候再試", "OK"); } } else { await DisplayAlert("訊息", app.errorMessage, "OK"); } } } else { await DisplayAlert("訊息", app.networkMessage, "OK"); } } else { await DisplayAlert("訊息", "激活碼有誤請重新輸入!", "OK"); } } else { await DisplayAlert("訊息", "請輸入激活碼或者裝置號碼!", "OK"); } } else { await DisplayAlert("訊息", "密碼不一致請重新輸入", "OK"); } } else { await DisplayAlert("訊息", "有必填欄位未輸入或格式錯誤!", "OK"); } } else { await DisplayAlert("訊息", "未勾選同意合約", "OK"); } }