public string Generate(SearchObject search) { string result = String.Format("{0}{1}?format=rss", search.SearchLocation.Url, search.Category.Key); foreach (KeyValuePair <string, string> kvp in search.SearchItems) { if (kvp.Value != null && kvp.Value.Length > 0) { var val = kvp.Value; //HACK: Needs improvement for removing $ if (val.Length > 0 && val.Substring(0, 1) == "$") { val = val.Substring(1, val.Length - 1); } result += String.Format("&{0}={1}", kvp.Key, val); } } foreach (KeyValuePair <object, KeyValuePair <object, object> > kvp in search.Conditions) { if (kvp.Value.Key != null) { result += String.Format("&{0}={1}", kvp.Value.Key, kvp.Value.Value); } } Console.WriteLine(result); return(result); }
public string Generate(SearchObject search) { string result = String.Format("{0}{1}?format=rss", search.SearchLocation.Url, search.Category.Key); foreach (KeyValuePair<string, string> kvp in search.SearchItems) { if (kvp.Value != null && kvp.Value.Length > 0) { var val = kvp.Value; //HACK: Needs improvement for removing $ if (val.Length > 0 && val.Substring(0, 1) == "$") val = val.Substring(1, val.Length - 1); result += String.Format("&{0}={1}", kvp.Key, val); } } foreach (KeyValuePair<object, KeyValuePair<object, object>> kvp in search.Conditions) { if (kvp.Value.Key != null) { result += String.Format("&{0}={1}", kvp.Value.Key, kvp.Value.Value); } } Console.WriteLine(result); return result; }
public string SecondFormatSearch(SearchObject searchObject) { string result = string.Empty; foreach (KeyValuePair<string, string> prop in searchObject.SearchItems) { if (prop.Value != null) result += String.Format("{0}: {1}, ", prop.Key, prop.Value); } foreach (KeyValuePair<object, KeyValuePair<object, object>> cond in searchObject.Conditions) { if (cond.Value.Key != null) result += String.Format("{0}: {1}, ", cond.Value.Key, cond.Key); } result = result.Trim(); if (searchObject.SearchItems.Count > 0 && result[result.Length - 1].Equals(',')) result = result.TrimEnd(','); return result.Length == 0 ? "all" : result; }
public async Task<bool> DeleteSearchAsync(String linkUrl, SearchObject searchObject) { var currentSerialized = JsonConvert.SerializeObject(searchObject); var search = conn.Table<Search>().Where(x => x.SerializedSearch.Equals(currentSerialized)).ToListAsync().Result.First(); if (search == null) Console.WriteLine("----------------------------------------------------------------------------------------------"); try { var result = await conn.DeleteAsync(search).ConfigureAwait(false); StatusMessage = string.Format("{0} dropped from database [Link: {1}]", result, linkUrl); StatusCode = codes.ok; return true; } catch (Exception ex) { StatusMessage = string.Format("Failed to delete record: {0}, Error: {1}", linkUrl, ex.Message); StatusCode = codes.bad; return false; } }
async void OnOptionItemSelected(object sender, OptionItemEventArgs e) { if (e.Item.TitleFormatted.ToString() == "Save") { SearchObject searchObject = new SearchObject(); searchObject.SearchLocation = location; searchObject.Category = SubCategory.Value != null ? new KeyValuePair<object, object>(SubCategory.Value, SubCategory.Key) : new KeyValuePair<object, object>(category.Key, category.Value); searchObject.SearchItems = this.SearchItems; searchObject.Conditions = this.Conditions; searchObject.MaxListings = this.MaxListings; searchObject.PostedDate = this.WeeksOld; string serialized = JsonConvert.SerializeObject(searchObject); await MainActivity.databaseConnection.AddNewSearchAsync(location.Url, serialized); Console.WriteLine(MainActivity.databaseConnection.StatusMessage); if (MainActivity.databaseConnection.StatusCode == Models.codes.ok) { Toast.MakeText(context, "Search Saved!", ToastLength.Short).Show(); } else { var message = string.Format("Oops, something went wrong{0}Please try again...", System.Environment.NewLine); Toast.MakeText(context, message, ToastLength.Short).Show(); } } }
void ProceedButton_Click(object sender, EventArgs e) { QueryGeneration queryHelper = new QueryGeneration(); SearchObject searchObject = new SearchObject(); searchObject.SearchLocation = location; searchObject.Category = SubCategory.Value != null ? new KeyValuePair<object, object>(SubCategory.Value, SubCategory.Key) : new KeyValuePair<object, object>(category.Key, category.Value); searchObject.SearchItems = this.SearchItems; searchObject.Conditions = this.Conditions; var transaction = ((AppCompatActivity)context).SupportFragmentManager.BeginTransaction(); SearchResultsFragment resultsFragment = new SearchResultsFragment(); resultsFragment.Query = queryHelper.Generate(searchObject); resultsFragment.MaxListings = MaxListings; resultsFragment.WeeksOld = WeeksOld; ((MainActivity)(this.context)).OptionItemSelected -= OnOptionItemSelected; transaction.Replace(Resource.Id.frameLayout, resultsFragment); transaction.AddToBackStack(null); transaction.Commit(); }
async void SaveButtonClicked(object sender, EventArgs e) { SearchObject searchObject = new SearchObject(); searchObject.SearchLocation = Location; searchObject.Category = SubCategory.Value != null ? new KeyValuePair<object, object>(SubCategory.Value, SubCategory.Key) : new KeyValuePair<object, object>(Category.Key, Category.Value); searchObject.SearchItems = this.SearchItems; searchObject.Conditions = this.Conditions; searchObject.MaxListings = this.MaxListings; searchObject.PostedDate = this.WeeksOld; string serialized = JsonConvert.SerializeObject(searchObject); await AppDelegate.databaseConnection.AddNewSearchAsync(Location.Url, serialized); serialized = null; Console.WriteLine(AppDelegate.databaseConnection.StatusMessage); if (AppDelegate.databaseConnection.StatusCode == codes.ok) { UIAlertView alert = new UIAlertView(); alert.Message = "Search Saved!"; alert.AddButton("OK"); alert.Show(); this.NavigationItem.RightBarButtonItem.Enabled = false; } else { UIAlertView alert = new UIAlertView(); alert.Message = string.Format("Oops, something went wrong{0}Please try again...", Environment.NewLine); alert.AddButton("OK"); alert.Show(); this.NavigationItem.RightBarButtonItem.Enabled = true; } searchObject = null; }
void SearchButton_Clicked(object sender, EventArgs e) { QueryGeneration queryHelper = new QueryGeneration(); var feedViewController = new SearchResultsViewController(); SearchObject searchObject = new SearchObject(); searchObject.SearchLocation = Location; searchObject.Category = SubCategory.Value != null ? new KeyValuePair<object, object>(SubCategory.Value, SubCategory.Key) : new KeyValuePair<object, object>(Category.Key, Category.Value); searchObject.SearchItems = this.SearchItems; searchObject.Conditions = this.Conditions; var query = queryHelper.Generate(searchObject); feedViewController.Query = query; feedViewController.MaxListings = MaxListings; feedViewController.WeeksOld = WeeksOld; this.ShowViewController(feedViewController, this); }