public EditDrinksPage() { InitializeComponent(); DataContext = App.ViewModel; Drink TapToAdd = new Drink() { Name = "Tap to add a drink", Size = 0, mg = 0, drinkId = 1, IsActive = false }; Drink AddedDrinks = new Drink() { Name = "------ Added Drinks ------", Size = 0, mg = 0 }; var drinkList = new List<Drink>(App.ViewModel.drinkList); int i; for (i = 0; i < drinkList.Count; i++) { if ((drinkList[i] as Drink).Name == "Tap to add a drink") { var drink = (drinkList[i] as Drink); if (drinkList.Contains(drink)) drinkList.Remove(drink); } else if ((drinkList[i] as Drink).Name == "------ Added Drinks ------") { var drink = (drinkList[i] as Drink); if (drinkList.Contains(drink)) drinkList.Remove(drink); } } drinkList.Remove(TapToAdd); if (drinkList.Contains(AddedDrinks)) drinkList.Remove(AddedDrinks); drinksListBox.ItemsSource = drinkList; }
public void DeleteDrink(Drink drink) { drinkList.Remove(drink); DrinkDB.Drinks.DeleteOnSubmit(drink); DrinkDB.SubmitChanges(); }
public void DeleteWish() { var drinkForDelete = new Drink(); ; // = this.SelectedDrink // Remove from the list drinkList.Remove(drinkForDelete); // Remove from the data context DrinkDB.Drinks.DeleteOnSubmit(drinkForDelete); // Save the database DrinkDB.SubmitChanges(); }
public void AddDrink(Drink newDrink) { // Add to the data context DrinkDB.Drinks.InsertOnSubmit(newDrink); // Save changes to database DrinkDB.SubmitChanges(); // Add to the drink list //drinkList.Add(newDrink); drinkList.Insert(1, newDrink); App.ViewModel.SaveChangesToDB(); }
private void AddDrinkButton_Click(object sender, RoutedEventArgs e) { if (drinkNameTxtBox.Text != "") { drinkName = drinkNameTxtBox.Text; } else { MessageBox.Show("Enter a drink name."); return; } #region If the text is a valid number, use that if (IsTextValidated(contentTxtBox.Text)) // check if it's numeric { drinkContent = Convert.ToInt32(contentTxtBox.Text); } else // Stay on the page and get a valid numberic value { MessageBoxResult m = MessageBox.Show("Please enter a numeric value."); contentTxtBox.Text = ""; return; } #endregion Drink newDrink = new Drink { Name = drinkName, mg = drinkContent }; int drinkListSize = App.ViewModel.drinkList.Count; (DataContext as DrinkViewModel).AddDrink(newDrink); // TODO: Add custom Notification Box for Yes/No //MessageBox.Show("Would you like to add this drink to the default drink list?", "", MessageBoxButton.OKCancel); NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); }