Пример #1
0
 private async void ShowLoginFormHandle(object sender, TappedRoutedEventArgs e)
 {
     ClearValue(SymbolIcon.ForegroundProperty);
     if (await GlobalHandle.checkToken() != null)
     {
         PageContent.Navigate(typeof(Views.UserInfomation));
     }
     else
     {
         PageContent.Navigate(typeof(Views.LoginForm));
     }
 }
Пример #2
0
        private async void ShowListSonngHandle(object sender, TappedRoutedEventArgs e)
        {
            if (await GlobalHandle.checkToken() != null)
            {
                PageContent.Navigate(typeof(Views.ListSong));
            }
            else
            {
                var messageDialog = new MessageDialog("Vui lòng đăng nhập để sử dụng tính năng");
                await messageDialog.ShowAsync();

                PageContent.Navigate(typeof(Views.LoginForm));
            }
        }
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (GlobalHandle.checkToken() != null)
            {
                this.token.token = await GlobalHandle.checkToken();

                Debug.WriteLine(this.token.token);

                var data            = Services.APIHandle.UserInfomationHandle(this.token.token);
                var responseContent = data.Result.Content.ReadAsStringAsync().Result;
                if (data.Result.StatusCode == HttpStatusCode.Created)
                {
                    Member currentMember = JsonConvert.DeserializeObject <Member>(responseContent);
                    lastName.Text  = currentMember.lastName;
                    firstName.Text = currentMember.firstName;
                    email.Text     = currentMember.email;
                    phone.Text     = currentMember.phone;
                    address.Text   = currentMember.address;
                    ImageUrl.Text  = currentMember.avatar;

                    //check Gender
                    switch (currentMember.gender)
                    {
                    case 1:
                        Gender_Male.IsChecked = true;
                        break;

                    case 0:
                        Gender_Female.IsChecked = true;
                        break;

                    case 2:
                        Gender_Other.IsChecked = true;
                        break;

                    default:
                        break;
                    }

                    //show pic
                    Uri u;

                    try
                    {
                        u = new Uri(currentMember.avatar, UriKind.Absolute);
                        Debug.WriteLine(u.AbsoluteUri);
                        ImageUrl.Text   = u.AbsoluteUri;
                        MyAvatar.Source = new BitmapImage(u);
                    } catch (Exception error)
                    {
                    }



                    //add birthday into form
                    BirthDay.Date = DateTime.ParseExact(currentMember.birthday, "yyyy-MM-ddT00:00:00.000+0000", CultureInfo.InvariantCulture);
                }
                else
                {
                    ErrorList error = JsonConvert.DeserializeObject <ErrorList>(responseContent);
                    Debug.WriteLine(responseContent);
                    Debug.WriteLine(error.error.Count);
                    if (error != null)
                    {
                        var content = error.message;
                        content += "\n Tài khoản hết hạn, vui lòng đăng nhập lại";

                        var messageDialog = new MessageDialog(content);
                        await messageDialog.ShowAsync();

                        //Xoa file token
                        GlobalHandle.deleteToken();
                        //Chuyen huong frame
                        this.Frame.Navigate(typeof(Views.LoginForm));
                    }
                }
            }
        }