private async Task SendLoginData ( string user , string password ) { dynamic login = new { user = user , password = password }; string result = await RestAPI.SendPostRequest ( login , RestAPI.publicApiAddress + "login/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { string data = JsonHelper.DecodeJson ( result ); newUser = JsonHelper.ConvertToUser ( data ); //save user token UserData.token = newUser.token; UserData.settings.Add ( AppSettings.keyToken , UserData.token ); //save user id UserData.id = newUser.id; if ( UserData.settings.Contain ( AppSettings.keyId ) ) UserData.settings.Update ( AppSettings.keyId , UserData.id ); else UserData.settings.Add ( AppSettings.keyId , UserData.id ); //save opened status if ( UserData.settings.Contain ( AppSettings.keyFirstOpen ) ) UserData.settings.Update ( AppSettings.keyFirstOpen , false ); else UserData.settings.Add ( AppSettings.keyFirstOpen , false ); //navigate to mainpage Frame.Navigate ( typeof ( MainPage ) ); } else { gridNotification.Show ( true , JsonHelper.GetJsonMessage ( result ) ); } }
private async void SendMessageTap ( object sender , TappedRoutedEventArgs e ) { string r = MessageValidation (); if ( r == "" && textBoxContent.Text.Length > 0 ) { //show progressbar ControlMethods.SwitchVisibility ( true , progressBar ); //send the message string toUserId = ( ( Button ) sender ).Tag.ToString (); dynamic dataToSend = new { toUserId = toUserId , fromUserId = UserData.id , message = textBoxContent.Text }; string result = await RestAPI.SendPostRequest ( dataToSend , RestAPI.publicApiAddress + "message/send/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { //clear message textBoxContent.Text = ""; } else { gridNotification.Show ( true ); } ControlMethods.SwitchVisibility ( false , progressBar ); gridSendMessage.Visibility = Visibility.Collapsed; scrollViewer.Visibility = Visibility.Visible; } else { gridNotification.Show ( true , r ); } }
private async void SendMessageTap ( object sender , TappedRoutedEventArgs e ) { //check length string r = CheckMessage (); if ( r == "" ) { string toUserId = ( ( Button ) sender ).Tag.ToString (); dynamic dataToSend = new { toUserId = toUserId , fromUserId = UserData.id , message = textBoxContent.Text }; string result = await RestAPI.SendPostRequest ( dataToSend , RestAPI.publicApiAddress + "message/send/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { string dateTime = JsonHelper.DecodeJson ( result ); Message newMes = new Message ( UserData.id , toUserId , textBoxContent.Text , dateTime ); currentConversations.messages.Add ( newMes ); textBoxContent.Text = ""; } else { gridNotification.Show ( true ); } } else gridNotification.Show ( true , r ); }
private async Task<RestAPI.ResponseStatus> MarkReadConversation ( string fromUserId ) { dynamic dataToSend = new { toUserId = UserData.id , fromUserId = fromUserId , }; string result = await RestAPI.SendPostRequest ( dataToSend , RestAPI.publicApiAddress + "message/conversation/" ); return JsonHelper.IsRequestSucceed ( result ); }
private async Task SendRequestToPost ( string postId , object sender ) { dynamic request = new { postId = postId , userId = UserData.id }; string result = await RestAPI.SendPostRequest ( request , RestAPI.publicApiAddress + "request/new/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { gridNotification.Show ( false , "Đã gửi yêu cầu" ); ( ( Button ) sender ).IsEnabled = false; } else { gridNotification.Show ( true ); } }
private async void AddToYourBook ( object sender , RoutedEventArgs e ) { ControlMethods.SwitchVisibility ( true , progressBar ); if ( ( ( Button ) sender ).Tag.ToString () == "0" ) { //add book dynamic book = new { bookId = bookId , userId = UserData.id }; string result = await RestAPI.SendPutRequest ( book , RestAPI.publicApiAddress + "booklist/add/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { ( ( Button ) sender ).Content = "Xóa"; ( ( Button ) sender ).Tag = 1; //#F44336 ( ( Button ) sender ).Background = new SolidColorBrush ( Color.FromArgb ( 255 , 244 , 67 , 54 ) ); } else { gridNotification.Show ( true ); } } else { //remove book dynamic book = new { bookId = bookId , userId = UserData.id }; string result = await RestAPI.SendPostRequest ( book , RestAPI.publicApiAddress + "booklist/remove/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { ( ( Button ) sender ).Content = "Thêm"; ( ( Button ) sender ).Tag = 0; //#4CAF50 ( ( Button ) sender ).Background = new SolidColorBrush ( Color.FromArgb ( 255 , 76 , 175 , 80 ) ); } else { gridNotification.Show ( true ); } } ControlMethods.SwitchVisibility ( false , progressBar ); }
private async void AddBook ( object sender , RoutedEventArgs e ) { string v = FieldValidation (); if ( v == "" ) { string imageString = await ImageUpload.StorageFileToBase64 ( file ); dynamic dataTosend = new { title = textBoxTitle.Text , author = suggestAuthor.Text , year = comboYear.SelectedValue , genreId = comboBoxGenre.SelectedValue , description = textBoxDes.Text , image = imageString , userId = UserData.id }; string result = await RestAPI.SendPutRequest ( dataTosend , RestAPI.publicApiAddress + "book/new/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { gridNotification.Show ( false , "Đã thêm sách mới" ); } else { gridNotification.Show ( true , JsonHelper.GetJsonMessage ( result ) ); } } else { gridNotification.Show ( true , v ); } }
private async void ChangePass ( object sender , RoutedEventArgs e ) { string r = CheckPasswordValid (); if ( r == "" ) { //ok dynamic dataToSend = new { userNewPass = pwBoxNew.Password , userId = UserData.id }; string result = await RestAPI.SendPostRequest ( dataToSend , RestAPI.publicApiAddress + "account/password/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { user.password = ComputeMD5 ( pwBoxNew.Password ); gridChangePass.Visibility = Visibility.Collapsed; mainScrollViewer.Visibility = Visibility.Visible; NavigationMethod.SetBackButtonVisibility ( false ); } else gridNotification.Show ( true ); } else { gridNotification.Show ( true , r ); } }
private async void SaveClick ( object sender , RoutedEventArgs e ) { string r = Fieldvalidation (); if ( r == "" ) { //UpdateLocalInfo (); string imageString = ""; if ( file != null ) imageString = await ImageUpload.StorageFileToBase64 ( file ); else imageString = ""; dynamic newUser = new { userId = UserData.id , email = textBoxEmail.Text , fullname = textBoxFullName.Text , address = textBoxAddress.Text , districtId = comboDistrict.SelectedValue , ava = imageString }; string result = await RestAPI.SendPostRequest ( newUser , RestAPI.publicApiAddress + "account/update/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { gridNotification.Show ( false , "Cập nhật thành công" ); user.districtId = comboDistrict.SelectedValue.ToString (); user.cityId = comboCity.SelectedValue.ToString (); //show new value DisplayUserInfo (); } else gridNotification.Show ( true ); } else { gridNotification.Show ( true , r ); } }
private async void DeleteRequest ( object sender , RoutedEventArgs e ) { ControlMethods.SwitchVisibility ( true , progressBar ); string postId = ( ( Button ) sender ).Tag.ToString (); dynamic data = new { postId = postId , userId = UserData.id }; string result = await RestAPI.SendPostRequest ( data , RestAPI.publicApiAddress + "request/delete/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { //send response succeed //remove request requestedPost.Remove ( requestedPost.First ( p => p.id == postId ) ); //check if posts in book is empty if ( requestedBooks.Any ( r => r.posts.Count == 0 ) ) //if true, remove the book requestedBooks.Remove ( requestedBooks.First ( r => r.posts.Count == 0 ) ); } else { //send response failed gridNotification.Show ( true ); } ControlMethods.SwitchVisibility ( false , progressBar ); }
private async Task<RestAPI.ResponseStatus> SendUserResponse ( bool isAccepted , string requestId ) { dynamic data = new { requestId = requestId , isAccepted = isAccepted }; string result = await RestAPI.SendPostRequest ( data , RestAPI.publicApiAddress + "request/respond/" ); if ( JsonHelper.IsRequestSucceed ( result ) == RestAPI.ResponseStatus.OK ) { return RestAPI.ResponseStatus.OK; } return RestAPI.ResponseStatus.Failed; }