public SearchRefenceModel GetSearchRefence() { SearchRefenceModel returnDefault = new SearchRefenceModel { user_id = Application.Current.Properties["Id"].ToString().Replace("\"", ""), distance_metric = 0, maximum_distance = "100", age_end = "100", age_start = "1" }; string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "databaseFolder"); System.IO.Directory.CreateDirectory(applicationFolderPath); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "amera.db"); using (SQLiteConnection conn = new SQLiteConnection(databaseFileName)) { conn.CreateTable <SearchRefenceModel>(); var table = conn.Table <SearchRefenceModel>().ToList(); foreach (SearchRefenceModel userModel in table) { return(userModel); } } return(returnDefault); }
protected async override void OnAppearing() { userSearchReference = sqliteManager.GetSearchRefence(); deleteSqliteData(); await refreshData(); //ClientWebSocket wsClient = new ClientWebSocket(); //await wsClient.ConnectAsync(new Uri("ws://" + ApiConnection.SocketUrl + ":8080"), CancellationToken.None); //while (wsClient.State == WebSocketState.Open) //{ // WebSocketReceiveResult result; // var message = new ArraySegment<byte>(new byte[4096]); // string receivedMessage; // do // { // result = await wsClient.ReceiveAsync(message, CancellationToken.None); // var messageBytes = message.Skip(message.Offset).Take(result.Count).ToArray(); // receivedMessage = System.Text.Encoding.UTF8.GetString(messageBytes); // var resultModel = JsonConvert.DeserializeObject<ChatModel>(receivedMessage); // if (resultModel.receiver_id == Application.Current.Properties["Id"].ToString().Replace("\"", "") || // resultModel.sender_id == Application.Current.Properties["Id"].ToString().Replace("\"", "")) // { // await refreshData(); // } // } // while (!result.EndOfMessage); //} }
private async Task retrieveSearchReference() { try { using (var cl = new HttpClient()) { string urlString = "http://" + ApiConnection.Url + "/apier/api/test_api.php?action=fetch_search_reference&id='" + Application.Current.Properties["Id"].ToString() + "'"; var request = await cl.GetAsync(urlString); request.EnsureSuccessStatusCode(); var response = await request.Content.ReadAsStringAsync(); //await DisplayAlert("Erro!", response.ToString(), "Okay"); if (response.ToString().Contains("Undefined")) { return; } var looper = JsonConvert.DeserializeObject <List <SearchRefenceModel> >(response); foreach (SearchRefenceModel model in looper) { userSearchReference = model; break; } await saveSearchToSqlite(); } } catch (Exception e) { return; } }
public ViewProfile(string id, bool isAlreadyLiked = false) { InitializeComponent(); searchRefence = sqliteManager.GetSearchRefence(); _isAlreadyLiked = isAlreadyLiked; userId = id; }
private async Task saveSearchToSqlite(SearchRefenceModel userSearchReference) { string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "databaseFolder"); System.IO.Directory.CreateDirectory(applicationFolderPath); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "amera.db"); using (SQLiteConnection conn = new SQLiteConnection(databaseFileName)) { conn.CreateTable <SearchRefenceModel>(); conn.Insert(userSearchReference); } }
private async Task saveToDatabase() { try { SearchRefenceModel searchReference = new SearchRefenceModel() { user_id = Application.Current.Properties["Id"].ToString().Replace("\"", ""), maximum_distance = slider.Value.ToString("0"), age_start = ageslider.LowerValue.ToString("0"), age_end = ageslider.UpperValue.ToString("0"), distance_metric = metric }; //Save to Remote Database var client = new HttpClient(); var form = new MultipartFormDataContent(); MultipartFormDataContent content = new MultipartFormDataContent(); content.Add(new StringContent(searchReference.user_id), "user_id"); content.Add(new StringContent(searchReference.maximum_distance), "maximum_distance"); content.Add(new StringContent(searchReference.age_start), "age_start"); content.Add(new StringContent(searchReference.age_end), "age_end"); content.Add(new StringContent(searchReference.distance_metric.ToString()), "distance_metric"); var request = await client.PostAsync("http://" + ApiConnection.Url + "/apier/api/test_api.php?action=update_search_reference", content); request.EnsureSuccessStatusCode(); var response = await request.Content.ReadAsStringAsync(); //Save to Local Database string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "databaseFolder"); System.IO.Directory.CreateDirectory(applicationFolderPath); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "amera.db"); using (SQLiteConnection conn = new SQLiteConnection(databaseFileName)) { conn.CreateTable <SearchRefenceModel>(); conn.Update(searchReference); } //Update user interest var userModel = sqliteManager.getUserModel(); userModel.interest = genderLookingFor().ToString(); //userModel.interest = showmePicker.SelectedIndex.ToString(); sqliteManager.updateUserModel(userModel); await api.updateUser(sqliteManager.getUserModel()); await Navigation.PopModalAsync(); } catch (Exception ex) { await DisplayAlert("Connection Error", "You are offline, Please check your internet connection. Any changes will not be applied", "Okay"); } }
public async Task retrieveSearchReference() { SearchRefenceModel modelInit = new SearchRefenceModel(); modelInit.user_id = Application.Current.Properties["Id"].ToString().Replace("\"", ""); try { string urlString = "http://" + ApiConnection.Url + "/apier/api/test_api.php?action=fetch_search_reference&id='" + Application.Current.Properties["Id"].ToString() + "'"; var request = await client.GetAsync(urlString); request.EnsureSuccessStatusCode(); var response = await request.Content.ReadAsStringAsync(); //await DisplayAlert("Erro!", response.ToString(), "Okay"); if (response.ToString().Contains("Undefined")) { await saveSearchToSqlite(modelInit); return; } if (response.ToString().Contains("null")) { await saveSearchToSqlite(modelInit); return; } if (string.IsNullOrWhiteSpace(response.ToString())) { await saveSearchToSqlite(modelInit); return; } var looper = JsonConvert.DeserializeObject <List <SearchRefenceModel> >(response); foreach (SearchRefenceModel model in looper) { modelInit = model; await saveSearchToSqlite(model); break; } await saveSearchToSqlite(modelInit); } catch (Exception) { Console.WriteLine("Error mga lods"); } }
private async void saveButton_Clicked(object sender, EventArgs e) { //Set to object SearchRefenceModel searchReference = new SearchRefenceModel() { user_id = Application.Current.Properties["Id"].ToString().Replace("\"", ""), maximum_distance = slider.Value.ToString("0"), age_range = ageslider.Value.ToString("0") }; //Save to Remote Database var client = new HttpClient(); var form = new MultipartFormDataContent(); MultipartFormDataContent content = new MultipartFormDataContent(); content.Add(new StringContent(searchReference.user_id), "user_id"); content.Add(new StringContent(searchReference.maximum_distance), "maximum_distance"); content.Add(new StringContent(searchReference.age_range), "age_range"); var request = await client.PostAsync("http://" + ApiConnection.Url + "/apier/api/test_api.php?action=update_search_reference", content); request.EnsureSuccessStatusCode(); var response = await request.Content.ReadAsStringAsync(); //Save to Local Database string applicationFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), "databaseFolder"); System.IO.Directory.CreateDirectory(applicationFolderPath); string databaseFileName = System.IO.Path.Combine(applicationFolderPath, "amera.db"); using (SQLiteConnection conn = new SQLiteConnection(databaseFileName)) { conn.CreateTable <SearchRefenceModel>(); conn.InsertOrReplace(searchReference); } await Navigation.PopModalAsync(); }