Example #1
0
        private async void LoginHandle(object sender, RoutedEventArgs e)
        {
            this.currentMember.email    = userEmail.Text;
            this.currentMember.password = password.Password;
            var data            = Services.APIHandle.LoginHandle(this.currentMember).Result;
            var responseContent = Services.APIHandle.LoginHandle(this.currentMember).Result.Content.ReadAsStringAsync().Result;

            //Debug.WriteLine(data.Result.Content.ReadAsStringAsync().Result);
            if (data.StatusCode == System.Net.HttpStatusCode.Created)
            {
                // save file...
                Debug.WriteLine(responseContent);


                // Luu token
                GlobalHandle.saveToken(responseContent);
                //save email last user
                GlobalHandle.saveLastUser(this.currentMember.email);
                //save passWord if check savebox
                if (savePassword.IsChecked == true)
                {
                    GlobalHandle.savePassWord(this.currentMember.password);
                }
                else
                {
                    if (await GlobalHandle.checkPassword() != null)
                    {
                        GlobalHandle.deletePassword();
                    }
                }
                //Change Account Name in splitView
                Services.GlobalHandle.changeAccountName();
                Services.GlobalHandle.ShowSignOutButton();

                // Next page
                this.Frame.Navigate(typeof(Views.UserInfomation));
            }
            else
            {
                ErrorList error = JsonConvert.DeserializeObject <ErrorList>(responseContent);
                Debug.WriteLine(responseContent);
                if (error != null && error.error.Count > 0)
                {
                    var content = "";
                    foreach (var key in error.error.Keys)
                    {
                        //var textMessage = this.FindName(key);
                        //if (textMessage == null)
                        //{
                        //    continue;
                        //}
                        content += error.error[key].ToString();


                        //TextBlock textBlock = textMessage as TextBlock;
                        //textBlock.Text = error.error[key];
                        //textBlock.Visibility = Visibility.Visible;
                    }
                    var messageDialog = new MessageDialog(content);
                    await messageDialog.ShowAsync();
                }
            }
        }
        private async void RegisterHandle(object sender, RoutedEventArgs e)
        {
            registerMember.address = address.Text;

            registerMember.email     = email.Text;
            registerMember.firstName = firstName.Text;

            registerMember.lastName = lastName.Text;
            registerMember.password = password.Password;
            registerMember.phone    = phone.Text;
            registerMember.avatar   = ImageUrl.Text;
            var data            = Services.APIHandle.RegisterHandle(registerMember);
            var responseContent = data.Result.Content.ReadAsStringAsync().Result;

            if (data.Result.StatusCode == HttpStatusCode.Created)
            {
                Debug.WriteLine(data.Result.Content.ReadAsStringAsync().Result);
                var messageDialog = new MessageDialog("Đăng ký thành công");
                await messageDialog.ShowAsync();

                //Auto Login
                var loginData            = Services.APIHandle.LoginHandle(registerMember).Result;
                var loginResponseContent = Services.APIHandle.LoginHandle(registerMember).Result.Content.ReadAsStringAsync().Result;
                // Luu token
                GlobalHandle.saveToken(loginResponseContent);
                //save email last user
                GlobalHandle.saveLastUser(registerMember.email);
                //Change account Name
                Services.GlobalHandle.changeAccountName();
                //Show Login Button
                Services.GlobalHandle.ShowSignOutButton();
                //Navigate Frame
                this.Frame.Navigate(typeof(Views.HomePage));
            }
            else
            {
                ErrorList error = JsonConvert.DeserializeObject <ErrorList>(responseContent);
                Debug.WriteLine(responseContent);
                if (error != null && error.error.Count > 0)
                {
                    var content = "";
                    foreach (var key in error.error.Keys)
                    {
                        //var textMessage = this.FindName(key);
                        //if (textMessage == null)
                        //{
                        //    continue;
                        //}
                        content += error.error[key].ToString();
                        content += "\n";


                        //TextBlock textBlock = textMessage as TextBlock;
                        //textBlock.Text = error.error[key];
                        //textBlock.Visibility = Visibility.Visible;
                    }
                    var messageDialog = new MessageDialog(content);
                    await messageDialog.ShowAsync();
                }
            }
        }