public void AddMealToDatabase(string name) { // TO-DO implement error handling. Check if already in database MealPlan mealPlan = new MealPlan(); Meal newMeal = new Meal() { MealName = NameInput }; mealPlan.Meals.InsertOnSubmit(newMeal); mealPlan.SubmitChanges(); IEnumerable <Meal> chosenMeal = from meal in mealPlan.Meals where meal.MealName == NameInput select meal; foreach (var meal in chosenMeal) { foreach (IngredientModel im in IngredientList) { if (im.IsChosen) { MealIngredient newMealIngredient = new MealIngredient() { MealID = meal.MealID, IngredientID = im.ID }; mealPlan.MealIngredients.InsertOnSubmit(newMealIngredient); mealPlan.SubmitChanges(); } } } }
public void DeleteMeal(object o) { MealPlan mealPlan = new MealPlan(); Meal meal = mealPlan.Meals.Single(m => m.MealName == MealModel.Name); mealPlan.Meals.DeleteOnSubmit(meal); mealPlan.SubmitChanges(); Mediator.NotifyColleagues("RepopulateMealList", null); Mediator.NotifyColleagues("RepopulateIngredientList", null); Mediator.NotifyColleagues("SwitchViewModel", new DefaultViewModel()); }
public void AddIngredientToDataBase(IngredientModel newIngred) { // TO-DO implement error handling. Check if already in database //Need to destroy on close as no longer using. MealPlan mealPlan = new MealPlan(); Ingredient newIngredient = new Ingredient() { IngredientName = newIngred.Name }; mealPlan.Ingredients.InsertOnSubmit(newIngredient); mealPlan.SubmitChanges(); Mediator.NotifyColleagues("SwitchViewModel", new DefaultViewModel()); }