private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            this.currentMember.email        = this.box_email.Text;
            this.currentMember.password     = this.pwd_password.Password;
            this.currentMember.firstName    = this.box_firstname.Text;
            this.currentMember.lastName     = this.box_lastname.Text;
            this.currentMember.phone        = this.box_email.Text;
            this.currentMember.address      = this.box_address.Text;
            this.currentMember.introduction = this.box_introduction.Text;
            this.currentMember.avatar       = this.txb_UrlImage.Text;
            var httpResponseMessage = APIHandle.Sign_Up(this.currentMember);

            if (httpResponseMessage.Result.StatusCode == HttpStatusCode.Created)
            {
                Debug.WriteLine("Success");
                await Handle.Login(currentMember.email, currentMember.password);

                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.Navigate(typeof(Views.ListViewDemo));
            }
            else
            {
                progress1.IsActive   = true;
                progress1.Visibility = Visibility.Visible;
                args.Cancel          = true;
                email.Text           = password.Text = phone.Text = lastName.Text = firstName.Text = avatar.Text = "";

                var errorJson = await httpResponseMessage.Result.Content.ReadAsStringAsync();

                ErrorResponse errResponse = JsonConvert.DeserializeObject <ErrorResponse>(errorJson);
                foreach (var errorField in errResponse.error.Keys)
                {
                    if (this.FindName(errorField) is TextBlock textBlock)
                    {
                        textBlock.Text = "*" + errResponse.error[errorField];
                        Debug.WriteLine("'" + errorField + "' : '" + errResponse.error[errorField] + "'");
                        textBlock.Visibility = Visibility.Visible;
                        textBlock.Foreground = new SolidColorBrush(Colors.Red);
                        textBlock.FontSize   = 10;
                        textBlock.FontStyle  = FontStyle.Italic;
                    }
                }
                progress1.IsActive   = false;
                progress1.Visibility = Visibility.Collapsed;
            }
        }
Exemplo n.º 2
0
        private async void Handle_Signup(object sender, RoutedEventArgs e)
        {
            if (Validate_Register())
            {
                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;

                var response = await APIHandle.Sign_Up(this.currentMember);

                var responseContent = await response.Content.ReadAsStringAsync();

                if (response.StatusCode == HttpStatusCode.Created)
                {
                    var rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(MainPage), null, new EntranceNavigationTransitionInfo());
                }
                else
                {
                    ErrorResponse errorObject = JsonConvert.DeserializeObject <ErrorResponse>(responseContent);
                    if (errorObject != null && errorObject.error.Count > 0)
                    {
                        foreach (var key in errorObject.error.Keys)
                        {
                            var textMessage = this.FindName(key);
                            if (textMessage == null)
                            {
                                continue;
                            }
                            TextBlock textBlock = textMessage as TextBlock;
                            textBlock.Text = errorObject.error[key];
                            Debug.WriteLine(errorObject.error[key]);
                            textBlock.Visibility = Visibility.Visible;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private async void Handle_Signup(object sender, TappedRoutedEventArgs e)
        {
            this.currentMember.email        = Email.Text;
            this.currentMember.password     = Password.Password;
            this.currentMember.introduction = Introduction.Text;
            this.currentMember.firstName    = FirstName.Text;
            this.currentMember.lastName     = LastName.Text;
            this.currentMember.avatar       = ImageUrl.Text;
            this.currentMember.phone        = Phone.Text;
            this.currentMember.address      = Address.Text;

            var httpResponseMessage = APIHandle.Sign_Up(this.currentMember);

            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);
            //}
        }