コード例 #1
0
ファイル: Sign.xaml.cs プロジェクト: vquyen96/asm_uwp
        private async void Handle_Signup(object sender, TappedRoutedEventArgs e)
        {
            this.currentMember.firstName    = this.FirstName.Text;
            this.currentMember.lastName     = this.LastName.Text;
            this.currentMember.email        = this.Email.Text;
            this.currentMember.password     = this.Password.Password.ToString();
            this.currentMember.avatar       = this.ImageUrl.Text;
            this.currentMember.phone        = this.Phone.Text;
            this.currentMember.address      = this.Address.Text;
            this.currentMember.introduction = this.Introduction.Text;

            bool validate = true;

            if (this.currentMember.email == "")
            {
                validate         = false;
                email.Text       = "Email khong duoc de trong!";
                email.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                Email.Focus(FocusState.Programmatic);
            }
            else
            {
                email.Text = "";
            }
            if (this.currentMember.password == "")
            {
                validate            = false;
                password.Text       = "Mat khau khong duoc de trong!";
                password.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                Password.Focus(FocusState.Programmatic);
            }
            else
            {
                password.Text = "";
            }
            if (Confirm_Password.Password.ToString() != Password.Password.ToString())
            {
                validate = false;
                Confirm_Password_Message.Text       = "Ban nhap lai mat khau khong dung";
                Confirm_Password_Message.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                Confirm_Password.Focus(FocusState.Programmatic);
            }
            else
            {
                Confirm_Password_Message.Text = "";
            }

            if (this.currentMember.firstName == "")
            {
                validate             = false;
                firstName.Text       = "firstName khong duoc de trong!";
                firstName.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                FirstName.Focus(FocusState.Programmatic);
            }
            else
            {
                firstName.Text = "";
            }

            if (this.currentMember.lastName == "")
            {
                validate            = false;
                lastName.Text       = "lastName khong duoc de trong!";
                lastName.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                LastName.Focus(FocusState.Programmatic);
            }
            else
            {
                lastName.Text = "";
            }

            if (this.currentMember.avatar == "")
            {
                validate          = false;
                avatar.Text       = "avatar khong duoc de trong!";
                avatar.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                ImageUrl.Focus(FocusState.Programmatic);
            }
            else
            {
                avatar.Text = "";
            }

            if (this.currentMember.address == "")
            {
                validate           = false;
                address.Text       = "Dia chi khong duoc de trong!";
                address.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                Address.Focus(FocusState.Programmatic);
            }
            else
            {
                address.Text = "";
            }

            if (this.currentMember.phone == "")
            {
                validate         = false;
                phone.Text       = "So dien thoai khong duoc de trong!";
                phone.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                Phone.Focus(FocusState.Programmatic);
            }
            else
            {
                phone.Text = "";
            }
            if (validate)
            {
                if (await ApiHandle.Sign_Up(this.currentMember))
                {
                    Debug.WriteLine("Action success.");
                    Login login = new Login();
                    await login.ShowAsync();
                }
                else
                {
                    validate         = false;
                    email.Text       = "Invalid email format!";
                    email.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
                    Email.Focus(FocusState.Programmatic);
                }
            }

            //if (httpResponseMessage.Result.StatusCode == HttpStatusCode.Created)
            //{
            //    Debug.WriteLine("Success");
            //}
            //else
            //{
            //    var errorJson = await httpResponseMessage.Result.Content.ReadAsStringAsync();
            //    ErrorResponse errResponse = JsonConvert.DeserializeObject<ErrorResponse>(errorJson);
            //    foreach (var errorField in errResponse.error.Keys)
            //    {
            //        TextBlock textBlock = this.FindName(errorField) as TextBlock;
            //        textBlock.Text = errResponse.error[errorField];
            //    }
            //}

            //Debug.WriteLine(jsonResult);
            //var rs = JObject.Parse(jsonResult);
            //if ((int)rs["status"] != 201)
            //{
            //    ErrorResponse errResponse = JsonConvert.DeserializeObject<ErrorResponse>(jsonResult);
            //    Debug.WriteLine(errResponse);
            //}
        }