private void SearchBtn_Click(object sender, RoutedEventArgs e) { if (searchItem.Text.All(char.IsDigit)) { MessageBox.Show("You cannot have any integers in your search term"); return; } if (searchItem.Text.All(char.IsSymbol) || searchItem.Text.All(char.IsPunctuation)) { MessageBox.Show("You cannot have any punctuation in your search term."); return; } string request = HttpUtility.UrlEncode(searchItem.Text); DishMetadata dishes = DishData.GetDishList(request); SelectDish(dishes); var beverages = FindBeverage.GetBeverage(); if (beverages == null) { return; } Beverages = beverages; var mostUsed = RankBeverage(); SavePairing(); SetBeverage(mostUsed); numberOfTimesRefreshed = 0; }
private void SelectDish(DishMetadata dishes) { DishViewer dw = new DishViewer(dishes); var result = dw.ShowDialog(); if (result != true) { MessageBox.Show("No dish was selected."); } }
public static DishMetadata GetDishList(string encodedRequest) { //HTTP request to recipepuppy to get dishes based on typed in value using (WebResponse wr = WebRequest.Create("http://www.recipepuppy.com/api/?q=" + encodedRequest).GetResponse()) { using (StreamReader sr = new StreamReader(wr.GetResponseStream())) { var result = sr.ReadToEnd(); DishMetadata json = JsonConvert.DeserializeObject <DishMetadata>(result); return(json); } } }
public DishViewer(DishMetadata dishes) { InitializeComponent(); this.Dishes = dishes.Dishes; this.DishList = new ObservableCollection <string>(); foreach (Dish d in dishes.Dishes) { DishList.Add(d.title); } this.dishLv.ItemsSource = DishList; DataContext = this; }