public void Delete(int id) { var recipeToRemove = _dbContext.Recipes.Where(e => e.Id == id) .Include(e => e.CookBookItems) .Include(e => e.Description) .First(); if (recipeToRemove != null) { _dbContext.Remove(recipeToRemove); _dbContext.SaveChanges(); } }
public void UpdateRecipeMealTypes(CookbookContext context, string[] selectedMealTypes, Recipe recipeToUpdate) { if (selectedMealTypes == null) { recipeToUpdate.RecipeAssignments = new List <RecipeAssignment>(); return; } var selectedMealTypesHS = new HashSet <string>(selectedMealTypes); var recipeMealTypes = new HashSet <int>(recipeToUpdate.RecipeAssignments.Select(r => r.Recipe.RecipeID)); foreach (var mealType in context.MealTypes) { if (!selectedMealTypesHS.Contains(mealType.ID.ToString())) { if (!recipeMealTypes.Contains(mealType.ID)) { recipeToUpdate.RecipeAssignments.Add( new RecipeAssignment { RecipeID = recipeToUpdate.RecipeID, MealTypeID = mealType.ID }); } } else { if (recipeMealTypes.Contains(mealType.ID)) { RecipeAssignment mealToRemove = recipeToUpdate .RecipeAssignments .SingleOrDefault(r => r.MealTypeID == mealType.ID); context.Remove(mealToRemove); } } } }
public void Delete(Ingredient entity) { _cookbookContext.Remove(entity); _cookbookContext.SaveChanges(); }
public void Delete(Recipe entity) { _cookbookContext.Remove(entity); _cookbookContext.SaveChanges(); }