Exemple #1
0
        private async void Do_Register(object sender, RoutedEventArgs e)
        {
            string text = await APIHandle.CheckCredential();

            if (text != "")
            {
                string token = await APIHandle.GetToken();

                if (token != "")
                {
                    ContentDialog noWifiDialog = new ContentDialog()
                    {
                        Title           = "Thông Báo",
                        Content         = "Bạn đã có tài khoản!",
                        CloseButtonText = "Ok"
                    };
                    await noWifiDialog.ShowAsync();
                }
            }
            else
            {
                Debug.WriteLine("name: " + this.Name);
                RegisterDialog register = new RegisterDialog();
                await register.ShowAsync();
            }
        }
Exemple #2
0
        private async void Do_Login(object sender, RoutedEventArgs e)
        {
            string text = await APIHandle.CheckCredential();

            if (text != "")
            {
                string token = await APIHandle.GetToken();

                if (token != "")
                {
                    ContentDialog noWifiDialog = new ContentDialog()
                    {
                        Title           = "Thông Báo",
                        Content         = "Bạn đã đăng nhập. \nVui lòng đăng xuất để đăng nhập tài khoản khác!",
                        CloseButtonText = "Ok"
                    };
                    await noWifiDialog.ShowAsync();
                }
            }
            else
            {
                LogInDialog login = new LogInDialog();
                await login.ShowAsync();
            }
        }
        private async void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            args.Cancel = true;
            try
            {
                var song = new Song()
                {
                    name        = song_name.Text,
                    thumbnail   = song_thumbnail.Text,
                    description = song_description.Text,
                    link        = song_link.Text,
                    author      = song_author.Text,
                    singer      = song_singer.Text
                };
                string token = await APIHandle.GetToken();

                var httpResponseMessage = APIHandle.Create_Song(song, "Basic", token);
                if (httpResponseMessage.Result.StatusCode == HttpStatusCode.Created)
                {
                    this.Hide();
                    ContentDialog noWifiDialog = new ContentDialog()
                    {
                        Title           = "Message",
                        Content         = "Upload Success.",
                        CloseButtonText = "Ok",
                    };
                    await noWifiDialog.ShowAsync();

                    Frame rootFrame = Window.Current.Content as Frame;
                    rootFrame.Navigate(typeof(Views.ListViewDemo));
                }
                else
                {
                    name.Text = author.Text = singer.Text = thumbnail.Text = link.Text = description.Text = "";

                    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;
                        if (textBlock != null)
                        {
                            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.Static;
                        }
                    }
                    Debug.WriteLine("Upload Fail");
                    Debug.WriteLine(args.Cancel);
                }
            }
            catch
            {
                Debug.WriteLine("Error");
            }
        }
Exemple #4
0
        //public async Task<string> GetToken()
        //{
        //    Windows.Storage.StorageFolder storageFolder =
        //                Windows.Storage.ApplicationData.Current.LocalFolder;
        //    Windows.Storage.StorageFile sampleFile =
        //        await storageFolder.GetFileAsync("credential.txt");
        //    string text = await Windows.Storage.FileIO.ReadTextAsync(sampleFile);
        //    Credential credential = JsonConvert.DeserializeObject<Credential>(text);
        //    string token = credential.token;
        //    return token;
        //}
        //public async void Test()
        //{
        //    var key = "Basic";
        //    var token = "elyXZcmdLKvJXiSXBN5n9xHG1HowA2gZtpEbae1YgFaRS7lovY3IvVCBWEyB6E2X";
        //    HttpClient httpClient = new HttpClient();
        //    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(key, token);
        //    var response = httpClient.GetAsync(APIUrl.API_INFORMATION);
        //    Debug.WriteLine(response.Result.Content.ReadAsStringAsync());
        //    information = JsonConvert.DeserializeObject<Information>(await response.Result.Content.ReadAsStringAsync());
        //    Debug.WriteLine(information.lastName);
        //}
        public async void GetInfo()
        {
            string text = await APIHandle.CheckCredential();

            if (text != "")
            {
                string token = await APIHandle.GetToken();

                Debug.WriteLine(token);
                if (token != "")
                {
                    this.login.Visibility   = Visibility.Collapsed;
                    this.account.Visibility = Visibility.Visible;
                    var httpResponseMessage = APIHandle.GetData(APIUrl.API_INFORMATION, "Basic", token);
                    var informationJson     = await httpResponseMessage.Result.Content.ReadAsStringAsync();

                    Debug.WriteLine(informationJson);
                    information = JsonConvert.DeserializeObject <Information>(informationJson);
                    Debug.WriteLine(information.lastName);
                    string[] date = information.birthday.Split('T');
                    this.txt_fullname.Text = (information.firstName + " " + information.lastName).ToUpper();
                    this.txt_birthday.Text = date[0];
                    this.txt_email.Text    = information.email;
                    //this.txt_address.Text = information.address;
                    //this.txt_intro.Text = information.introduction;
                    this.img_avatar.ImageSource = new BitmapImage(new Uri(information.avatar, UriKind.Absolute));
                }
                Debug.WriteLine(text);
            }
            else
            {
                this.account.Visibility = Visibility.Collapsed;
                this.login.Visibility   = Visibility.Visible;
                this.txt_fullname.Text  = "...";
                this.txt_birthday.Text  = "...";
                this.txt_email.Text     = "...";
                //this.txt_address.Text = "...";
                //this.txt_intro.Text = "...";
                //this.txt_gender.Text = "...";
                Debug.WriteLine("Token not exits");
                Debug.WriteLine(text);
            }
        }
        private async void GetInfo()
        {
            string text = await APIHandle.CheckCredential();

            if (text != "")
            {
                string token = await APIHandle.GetToken();

                Debug.WriteLine(token);
                if (token != "")
                {
                    var httpResponseMessage = APIHandle.GetData(APIUrl.API_INFORMATION, "Basic", token);
                    Debug.WriteLine(httpResponseMessage.Result.StatusCode);
                    //Debug.WriteLine(httpResponseMessage);
                    if (httpResponseMessage.Result.StatusCode == HttpStatusCode.Created)
                    {
                        var informationJson = await httpResponseMessage.Result.Content.ReadAsStringAsync();

                        Debug.WriteLine(HttpStatusCode.Created);
                        information = JsonConvert.DeserializeObject <Information>(informationJson);
                        string[] date = information.birthday.Split('T');
                        this.txt_fullname.Text = (information.firstName + " " + information.lastName).ToUpper();
                        this.txt_birthday.Text = "Birthday: " + date[0];
                        this.txt_email.Text    = "Email: " + information.email;
                        this.txt_phone.Text    = "Phone: " + information.phone;
                        try
                        {
                            this.img_avatar.ProfilePicture = new BitmapImage(new Uri(information.avatar, UriKind.Absolute));
                        } catch
                        {
                        }
                    }
                }
                Debug.WriteLine(text);
            }
        }