public bool AddFood(RestaurantBlock restInfo, Food food, int quantity = 1) { if (restaurant != restInfo && foodList.Count > 0) return false; restaurant = restInfo; //use copy to instead int idx; for (idx = 0; idx < foodList.Count; idx++) { if (foodList[idx].food == food) { var entity = foodList[idx]; entity.quantity += quantity; break; } } if (idx >= foodList.Count) { foodList.Add(new FoodEntity() { food = food, quantity = quantity }); } UpdatePrice(); return true; }
public bool RemoveFood(RestaurantBlock restInfo, Food food, int quantity = 1) { if (restaurant != restInfo) return false; for (int idx = 0; idx < foodList.Count; idx++) { if (foodList[idx].food == food) { var entity = foodList[idx]; if (entity.quantity > quantity) { entity.quantity -= quantity; } else foodList.RemoveAt(idx); UpdatePrice(); return true; } } return false; }
private void RestaurantBtn_Click(object sender, RoutedEventArgs e) { RestaurantBlock rest = (sender as Button).DataContext as RestaurantBlock; //string url = String.Format("{0}/{1}", eleAPI.host, rest.name_for_url); //WebBrowserTask webBrowserTask = new WebBrowserTask(); //webBrowserTask.Uri = new Uri(url); //webBrowserTask.Show(); restCache = rest; NavigationService.Navigate(new Uri("/Views/MenuListPage.xaml", UriKind.Relative)); }