private async void BtnLogin_OnClick(object sender, RoutedEventArgs e) { Member member = new Member(); member.email = txtEmail.Text; member.password = txtPassword.Password; var content = ApiHandle.Login(member); if (content.Result.IsSuccessStatusCode) { txtError.Foreground = new SolidColorBrush(Colors.Green); txtError.Text = "Login Success!!!!!"; await Task.Delay(1000); CurrentUser.currentUser = await ApiHandle.GetCurUser(member.email); Debug.WriteLine(CurrentUser.currentUser.address); if (CurrentUser.currentUser.Role_id == 1) { var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(TravellerBoard)); } else if (CurrentUser.currentUser.Role_id == 2) { var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(GuideBoard)); } } else { txtError.Foreground = new SolidColorBrush(Colors.Red); txtError.Text = "Login Faild!!!!"; } }
private async void SignUp(object sender, RoutedEventArgs e) { try { this.currentSong.name = this.Name.Text; this.currentSong.description = this.Description.Text; this.currentSong.singer = this.Singer.Text; this.currentSong.author = this.Author.Text; this.currentSong.thumbnail = this.Thumbnail.Text; this.currentSong.link = this.Link.Text; } catch (Exception ex) { await ApiHandle.Create_Song(this.currentSong); var dialog = new MessageDialog("Upload Success"); dialog.Title = "Really?"; dialog.Commands.Add(new UICommand { Label = "Ok", Id = 0 }); var res = await dialog.ShowAsync(); } Debug.WriteLine("Action success."); if (this.Name.Text == "" && this.Description.Text == "" && this.Singer.Text == "" && this.Author.Text == "" && this.Thumbnail.Text == "" && this.Link.Text == "") { this.error_Info.Text = "Thông tin không được để trống"; } }
private async void Handle_SignUp(object sender, RoutedEventArgs e) { CheckValid valid = new CheckValid(); currentMember.firstName = this.FirstName.Text; currentMember.lastName = this.LastName.Text; currentMember.email = this.Email.Text; currentMember.password = this.Password.Password.ToString(); currentMember.avatar = this.Avatar_Url.Text; currentMember.phone = this.Phone.Text; currentMember.address = this.Address.Text; Debug.WriteLine("First Name" + this.FirstName.Text); Debug.WriteLine(this.LastName.Text); Debug.WriteLine(this.Address.Text); if (!valid.CheckValidAll(currentMember)) { List <TextBlock> listMessage = new List <TextBlock>(); foreach (KeyValuePair <string, string> entry in valid.listError) { var message = this.FindName(entry.Key); TextBlock textBlock = message as TextBlock; textBlock.Text = entry.Value; textBlock.Visibility = Visibility.Visible; } } else { string response = await ApiHandle.Sign_Up(currentMember); Debug.WriteLine(response); Debug.WriteLine("OK"); } }
private async void Capture_Photo(object sender, RoutedEventArgs e) { StorageFile file = null; CameraCaptureUI captureUI = new CameraCaptureUI(); captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png; captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); file = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo); if (file == null) { return; } Uri URL = await ApiHandle <string> .Upload(file, await ApiHandle <string> .Call(APITypes.GetUpload, null), "quanganh9x", "image/png"); ImageUrl.Text = URL.AbsoluteUri; try { MyAvatar.Source = new BitmapImage(URL); isImageValid = true; avatar.Visibility = Visibility.Collapsed; } catch { ExceptionHandle.ThrowDebug("cant upload image"); MyAvatar.Source = null; isImageValid = false; avatar.Visibility = Visibility.Visible; } }
private async void OneDay_OnLoaded(object sender, RoutedEventArgs e) { try { var postion = await LocationData.getPosition(); #pragma warning disable CS0618 // Type or member is obsolete var lat = postion.Coordinate.Latitude; #pragma warning restore CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete var lon = postion.Coordinate.Longitude; #pragma warning restore CS0618 // Type or member is obsolete OpenWeatherMap1day.RootObject myWeather = await ApiHandle.GetWeatherOneDay(lat, lon); Debug.WriteLine(myWeather); string icon = string.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon); ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute)); TempTextBlock.Text = myWeather.main.temp.ToString(); DescriptionTextBlock.Text = myWeather.weather[0].description; LocationTextBlock.Text = myWeather.name; } catch (Exception ex) { Debug.WriteLine("Can not connect to API"); } }
private async void BtnRegister_OnClick(object sender, RoutedEventArgs e) { Member user = new Member(); user.email = this.txtEmail.Text; user.password = this.txtPassword.Password; user.address = this.txtAddress.Text; user.phone = this.txtPhone.Text; user.dob = this.DoBCalenderPicker.Date.Value.ToString("MM-dd-yyyy"); user.firstName = this.txtFirstName.Text; user.lastName = this.txtLastName.Text; var content = ApiHandle.Register(user); if (content.Result.IsSuccessStatusCode) { txtError.Foreground = new SolidColorBrush(Colors.Green); txtError.Text = "Register Success!!!!"; await Task.Delay(1000); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(MainPage)); } else { txtError.Foreground = new SolidColorBrush(Colors.Red); txtError.Text = "Register Failed!!!!"; } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { //await ApiHandle.Get_Mine_Song(); //var token = JsonConvert.DeserializeObject<>(contents); //Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder; //StorageFile sampleFile = await localFolder.GetFileAsync("token.txt"); //Debug.WriteLine(sampleFile); //string timestamp = await FileIO.ReadTextAsync(sampleFile); //TokenResponse token = JsonConvert.DeserializeObject<TokenResponse>(timestamp); //Debug.WriteLine(token.token); //HttpClient client2 = new HttpClient(); //client2.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", token.token); //var resp = client2.GetAsync("http://2-dot-backup-server-002.appspot.com/_api/v2/members/information").Result; //Debug.WriteLine(resp); //Debug.WriteLine(resp.StatusCode); //Debug.WriteLine(System.Net.HttpStatusCode.Created); if (await ApiHandle.Check_info()) { var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(view.ListView)); } else { Login login = new Login(); await login.ShowAsync(); } }
private async void Handle_Signup(object sender, RoutedEventArgs e) { var flag = 0; if (this.Email.Text == null || this.Email.Text == "") { Email_Error.Text = "(*)"; flag = 1; } if (this.FirstName == null || this.FirstName.Text == "") { FirstName_Error.Text = "(*)"; flag = 1; } if (this.LastName.Text == null || this.LastName.Text == "") { LastName_Error.Text = "(*)"; flag = 1; } if (this.Phone.Text == null || this.Phone.Text == "") { Phone_Error.Text = "(*)"; flag = 1; } if (flag == 0) { currentMember.firstName = this.FirstName.Text; currentMember.lastName = this.LastName.Text; currentMember.email = this.Email.Text; currentMember.password = this.Password.Password.ToString(); currentMember.avatar = this.ImageUrl.Text; currentMember.phone = this.Phone.Text; currentMember.address = this.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]; //} } } else { Register_error.Text = "Fields (*) can not be null"; } }
private async void BtnSignup_Click_1(object sender, RoutedEventArgs e) { // do validate first. this.currentSong.name = this.Name.Text; this.currentSong.description = this.Description.Text; this.currentSong.singer = this.Singer.Text; this.currentSong.author = this.Author.Text; this.currentSong.thumbnail = this.Thumbnail.Text; this.currentSong.link = this.Link.Text; await ApiHandle.Create_Song(this.currentSong); Debug.WriteLine("Action success."); }
private async void Handle_Signup(object sender, RoutedEventArgs 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; validateRegister(); await ApiHandle.Sign_Up(this.currentMember); }
private async void Log_in(object sender, RoutedEventArgs e) { if (this.Username.Text == null || this.Username.Text == "" || this.Password_login.Password == null || this.Password_login.Password == "") { Login_Error.Text = "Email & Password can not be null!"; } else { var httpResponseMessage = ApiHandle.Sign_In(Username.Text, Password_login.Password); var responseContent = await httpResponseMessage.Content.ReadAsStringAsync(); if (httpResponseMessage.StatusCode == HttpStatusCode.Created) { // save file... Debug.WriteLine(responseContent); // Doc token TokenResponse token = JsonConvert.DeserializeObject <TokenResponse>(responseContent); // Luu token StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync("token.txt", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, responseContent); Debug.WriteLine("login success!"); } else { // Xu ly loi. //errorresponse errorobject = jsonconvert.deserializeobject<errorresponse>(responsecontent); //if (errorobject != null && errorobject.error.count > 0) //{ // foreach (var key in errorobject.error.keys) // { // var textmessage = findname(key); // if (textmessage == null) // { // continue; // } // textblock textblock = textmessage as textblock; // textblock.text = errorobject.error[key]; // textblock.visibility = visibility.visible; // } //} //Debug.WriteLine(errorObject); } } }
private async void Handle_Signup(object sender, RoutedEventArgs 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; await ApiHandle.Sign_Up(this.currentMember); MessageDialog msDialog = new MessageDialog("Thành công"); msDialog.ShowAsync(); }
private async void Handle_Signup(object sender, RoutedEventArgs e) { // do validate first. 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; await ApiHandle.Sign_Up(this.currentMember); this.Frame.Navigate(typeof(LoginForm)); }
private async void Handle_Signup(object sender, TappedRoutedEventArgs e) { Dictionary <String, String> LoginInfor = new Dictionary <string, string>(); LoginInfor.Add("email", this.Email.Text); LoginInfor.Add("password", this.Password.Password); LoginInfor.Add("Confirm_Password_Message", this.Confirm_Password.Password); LoginInfor.Add("firstName", this.FirstName.Text); LoginInfor.Add("lastName", this.LastName.Text); LoginInfor.Add("avatar", this.ImageUrl.Text); LoginInfor.Add("phone", this.Phone.Text); LoginInfor.Add("address", this.Address.Text); 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 a Duy"); } 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); //} }
private void Handle_Signup(object sender, RoutedEventArgs e) { // do validate first. 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; if (ApiHandle.Sign_Up(this.currentMember)) { Debug.WriteLine("Action success."); } }
private async void MainPage_OnLoaded(object sender, RoutedEventArgs e) { try { Account.RootObject account = await ApiHandle.GetAccount(); txtTitle.Text = account.items[0].snippet.title; Image image = new Image(); image.Source = new BitmapImage(new Uri(account.items[0][email protected], UriKind.Absolute)); btnImage.Content = image; } catch (Exception ex) { Debug.WriteLine("Can not connect to API"); } }
private async void Login_Button(object sender, RoutedEventArgs e) { var username = Username.Text; var password = Password.Password; if (username == "") { Username_Message.Text = "Username is empty."; } else { Username_Message.Text = ""; this.account.username = username; }; if (password == "") { Password_Message.Text = "Password is empty."; } else { Password_Message.Text = ""; this.account.password = password; }; if (Username_Message.Text == "" && Password_Message.Text == "") { Response_Login.Text = ""; ResultAPI response = await ApiHandle.Sign_In(this.account); JObject data = JObject.Parse(response.Data); var errorCode = response.Status; if (errorCode == "Unauthorized") { Response_Login.Text = data.SelectToken("error").ToString(); } else { this.Frame.Navigate(typeof(Frames.MainSiinMusic)); StorageFolder folder = ApplicationData.Current.LocalFolder; StorageFile file = await folder.CreateFileAsync("config_login.json", CreationCollisionOption.ReplaceExisting); await FileIO.WriteTextAsync(file, data.ToString()); } } }
private async void SignUp(object sender, RoutedEventArgs e) { Dictionary <String, String> SongInfo = new Dictionary <string, string>(); SongInfo.Add("singer", this.Singer.Text); SongInfo.Add("link", this.Link.Text); this.currentSong.name = this.Name.Text; this.currentSong.description = this.Description.Text; this.currentSong.singer = this.Singer.Text; this.currentSong.author = this.Author.Text; this.currentSong.thumbnail = this.Thumbnail.Text; this.currentSong.link = this.Link.Text; validatSong(); await ApiHandle.Create_Song(this.currentSong); Debug.WriteLine("Action success."); }
private async void Handle_Signup(object sender, RoutedEventArgs e) { // do validate first. 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; await ApiHandle.Sign_Up(this.currentMember); if (this.Email.Text == "") { this.Email_Message.Text = "Please enter email"; } if (this.Password.ToString() == "") { this.Password_Message.Text = "Please enter password"; } if (this.FirstName.Text == "") { this.First_Message.Text = "Please enter firstname"; } if (this.LastName.Text == "") { this.LastName.Text = "Please enter lastname"; } if (this.Introduction.Text == "") { this.Introduction_Message.Text = "Please enter introduction"; } if (this.Address.Text == "") { this.Address_Message.Text = "Please enter address"; } if (this.Phone.Text == "") { this.Phone_Message.Text = "Please enter phone"; } Debug.WriteLine("Action success."); }
private async void Do_Register(object sender, TappedRoutedEventArgs e) { this.currentMember.firstName = this.FirstName.Text; this.currentMember.lastName = this.LastName.Text; this.currentMember.avatar = this.AvatarUrl.Text; this.currentMember.address = this.Address.Text; this.currentMember.introduction = this.Introduction.Text; this.currentMember.phone = this.Phone.Text; this.currentMember.email = this.Email.Text; this.currentMember.password = this.Password.Password; var httpResponseMessage = ApiHandle.Sign_Up(this.currentMember); if (httpResponseMessage.Result.StatusCode == HttpStatusCode.Created) { IsValidate = true; var dialog = new Windows.UI.Popups.MessageDialog("Bạn đã tạo mới tài khoản thành công"); dialog.Commands.Add(new Windows.UI.Popups.UICommand("Đóng") { Id = 1 }); dialog.CancelCommandIndex = 1; await dialog.ShowAsync(); } else { var errorJson = await httpResponseMessage.Result.Content.ReadAsStringAsync(); Error errResponse = JsonConvert.DeserializeObject <Error>(errorJson); if (errResponse.error.Count > 0) { foreach (var errorField in errResponse.error.Keys) { if (this.FindName(errorField) is TextBlock textBlock) { textBlock.Text = "* " + errResponse.error[errorField]; textBlock.Visibility = Visibility.Visible; textBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); } } } } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (ApiHandle <string> .CheckToken() != null) { rootFrame.Navigate(typeof(Views.NavigationView), e.Arguments); } else { rootFrame.Navigate(typeof(Views.LoginForm), e.Arguments); } } // Ensure the current window is active Window.Current.Activate(); } }
private async void Add_Song(object sender, RoutedEventArgs e) { this.currentSong.name = NameSong.Text; this.currentSong.description = Description.Text; this.currentSong.singer = Singer.Text; this.currentSong.author = Author.Text; this.currentSong.thumbnail = ThumbnailURL.Text; this.currentSong.link = LinkSong.Text; var httpResponse = ApiHandle.Create_Song(this.currentSong); if (httpResponse.Result.StatusCode == HttpStatusCode.Created) { var dialog = new Windows.UI.Popups.MessageDialog("You created a new song successfully"); dialog.Commands.Add(new Windows.UI.Popups.UICommand("Closed") { Id = 1 }); dialog.CancelCommandIndex = 1; await dialog.ShowAsync(); } else { var errorJson = await httpResponse.Result.Content.ReadAsStringAsync(); Error errResponse = JsonConvert.DeserializeObject <Error>(errorJson); if (errResponse.error.Count > 0) { foreach (var errorField in errResponse.error.Keys) { if (this.FindName(errorField) is TextBlock textBlock) { textBlock.Text = "* " + errResponse.error[errorField]; textBlock.Visibility = Visibility.Visible; textBlock.Foreground = new SolidColorBrush(Windows.UI.Colors.Red); } } } } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { try { if (NetworkInterface.GetIsNetworkAvailable()) { var postion = await ApiHandle.GetPosition(); #pragma warning disable CS0618 // Type or member is obsolete var lat = postion.Coordinate.Latitude; #pragma warning restore CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete var lon = postion.Coordinate.Longitude; #pragma warning restore CS0618 // Type or member is obsolete OpenWeatherMap.RootObject forecast = await ApiHandle.GetWeather(lat, lon); CityTextBlock.Text = forecast.city.name; for (int i = 0; i < forecast.list.Count; i++) { //collection.Add(forecast.list[i]); for (int j = 0; j < forecast.list[i].weather.Count; j++) { string icon = string.Format("ms-appx:///Assets/Weather/{0}.png", forecast.list[i].weather[j].icon); var listReplace = forecast.list[i].weather[j]; listReplace.icon = icon; } collection.Add(forecast.list[i]); } ForeCastGridView.ItemsSource = collection; } } catch (Exception exception) { Debug.WriteLine(exception); } }
private async void BtnNext_OnClick(object sender, RoutedEventArgs e) { CreateParameters parameters = new CreateParameters(); Posts post = new Posts(); List <Tag> listTags = new List <Tag>(); Tag tag = new Tag(); post.title = txtTitlePost.Text; post.content = txtContent.Text; post.Traveler_id = CurrentUser.currentUser.id; string[] spit = txtTags.Text.Split(new[] { "," }, StringSplitOptions.None); for (int i = 0; i < spit.Length; i++) { tag.tag_name = spit[i].Trim(); listTags.Add(tag); } parameters.Post = post; parameters.Tag = listTags; var content = ApiHandle.AddPost(parameters); if (content.Result.IsSuccessStatusCode) { txtError.Foreground = new SolidColorBrush(Colors.Green); txtError.Text = "Add Post Success!!!! Next Step"; await Task.Delay(1000); var rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(ImagePost)); } else { txtError.Foreground = new SolidColorBrush(Colors.Red); txtError.Text = "Add Post Failed!!!!"; } }
private async void BtnLogin_Click(object sender, RoutedEventArgs e) { if (CheckLogin(this.Email.Text)) { Revert(); Dictionary <String, String> LoginInfo = new Dictionary <string, string>(); LoginInfo.Add("email", this.Email.Text); LoginInfo.Add("password", this.Password.Password); string responseContent = await ApiHandle <Dictionary <string, string> > .Call(APITypes.SignIn, LoginInfo); try { Response resp = JsonConvert.DeserializeObject <Response>(responseContent); if (resp.token != null) { if (rem.IsChecked == true) { await FileHandle.Save("token.ini", resp.token); } FrameSwitcher.Switch(typeof(Views.NavigationView)); } else { Entity.Exception err = JsonConvert.DeserializeObject <Entity.Exception>(responseContent); login.Text = err.message; login.Visibility = Visibility.Visible; } } catch { ApiHandle <string> .ThrowException(responseContent); } } else { email.Visibility = Visibility.Visible; } }
private async void Handle_Signup(object sender, RoutedEventArgs e) { if (CheckRegister(this.Email.Text, this.Phone.Text)) { Revert(); this.currentMember.firstName = this.FirstName.Text; this.currentMember.lastName = this.LastName.Text; this.currentMember.email = this.Email.Text; this.currentMember.password = this.Password.Password; this.currentMember.avatar = this.ImageUrl.Text; this.currentMember.phone = this.Phone.Text; this.currentMember.address = this.Address.Text; this.currentMember.introduction = this.Introduction.Text; string responseContent = await ApiHandle <Member> .Call(APITypes.SignUp, this.currentMember); try { Member resp = JsonConvert.DeserializeObject <Member>(responseContent); if (resp.email != null && resp.email == this.currentMember.email) { await Dialog.Show("Register success!"); FrameSwitcher.Switch(typeof(Views.LoginForm)); } else { Entity.Exception err = JsonConvert.DeserializeObject <Entity.Exception>(responseContent); register.Text = err.message; register.Visibility = Visibility.Visible; } } catch { ApiHandle <string> .ThrowException(responseContent); } } }
private async void BtnSignup_Click(object sender, RoutedEventArgs e) { if (CheckSong(this.Link.Text)) { Service.ProgressBar.SetProgress(40, true); Revert(); this.currentSong.name = this.Name.Text; this.currentSong.description = this.Description.Text; this.currentSong.singer = this.Singer.Text; this.currentSong.author = this.Author.Text; this.currentSong.thumbnail = this.Thumbnail.Text; this.currentSong.link = this.Link.Text; Service.ProgressBar.SetProgress(60, true); string responseContent = await ApiHandle <Song> .Call(APITypes.CreateSong, this.currentSong); try { Song resp = JsonConvert.DeserializeObject <Song>(responseContent); if (resp.link != null && resp.link == this.currentSong.link) { await Dialog.Show("Add song success!"); } else { song.Visibility = Visibility.Visible; } } catch { ApiHandle <string> .ThrowException(responseContent); } finally { Service.ProgressBar.Hide(); } } }
private async void MainPage_OnLoaded(object sender, RoutedEventArgs e) { ProgressRing.IsActive = true; ProgressRing.Visibility = Visibility.Visible; for (int i = 15; i >= 1; i--) { await Task.Delay(1000); } ProgressRing.IsActive = false; ProgressRing.Visibility = Visibility.Collapsed; try { if (NetworkInterface.GetIsNetworkAvailable()) { List <string> contentList = new List <string>(); List <NewsEntity.RootObject> newList = await ApiHandle.GetNews(); for (int i = 0; i < newList.Count; i++) { string removeHtml = RemoveHtmlTag(newList[i].content.rendered); var splitContent = removeHtml.Split('.'); var shortConent = splitContent[0] + "." + splitContent[1] + "." + splitContent[2] + "." + splitContent[3]; newList[i].content.rendered = shortConent; collection.Add(newList[i]); } NewsGridView.ItemsSource = collection; } } catch (Exception exception) { Debug.WriteLine(exception); } }
private async void Handle_Signup(object sender, RoutedEventArgs e) { Dictionary <String, String> RegisterInfor = new Dictionary <string, string>(); RegisterInfor.Add("email", this.Email.Text); RegisterInfor.Add("firstName", this.FirstName.Text); RegisterInfor.Add("lastName", this.LastName.Text); 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; await ApiHandle.Sign_Up(this.currentMember); HttpClient httpClient = new HttpClient(); StringContent content = new StringContent(JsonConvert.SerializeObject(RegisterInfor), System.Text.Encoding.UTF8, "application/json"); var response = httpClient.PostAsync(API_Register, content).Result; var responseContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("Action success."); 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]; textBlock.Visibility = Visibility.Visible; } } if (this.Email.Text == "") { this.error_Email.Text = "Please enter introduction"; this.email.Visibility = Visibility.Collapsed; } else { this.email.Visibility = Visibility.Visible; }; if (this.Password.ToString() == "") { this.error_Password.Text = "Please enter introduction"; } if (this.FirstName.Text == "") { this.error_Fname.Text = "Please enter introduction"; this.firstName.Visibility = Visibility.Collapsed; } else { this.firstName.Visibility = Visibility.Visible; }; if (this.LastName.Text == "") { this.error_Lname.Text = "Please enter introduction"; this.lastName.Visibility = Visibility.Collapsed; } else { this.lastName.Visibility = Visibility.Visible; } if (this.Introduction.Text == "") { this.error_Intro.Text = "Please enter introduction"; } if (this.Address.Text == "") { this.error_Add.Text = "Please enter introduction"; } if (this.Phone.Text == "") { this.error_Phone.Text = "Please enter introduction"; } }
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); //} }