public async Task <IActionResult> PutIngredient(int recipeId, int ingredientId, [FromBody] Ingredient ingredient) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (ingredientId != ingredient.Id) { return(BadRequest()); } var recipe = _context.Recipes.FirstOrDefault(q => q.Id == recipeId); ingredientId = ingredient.Id; _context.Entry(ingredient).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IngredientExists(recipeId, ingredientId)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Update(Review item) { using (var context = new CookBookContext()) { if (item != null) { context.Entry(item).State = EntityState.Modified; context.SaveChanges(); } } }
public async Task <IActionResult> PutRecipe(int id, [FromBody] Recipe recipe) { recipe.Id = id; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != recipe.Id) { return(BadRequest()); } _context.Entry(recipe).State = EntityState.Modified; var existingRecipe = _context.Recipes.FirstOrDefault(q => q.Id == id); existingRecipe = recipe; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }
public bool DeleteRecipe(Recipe recipe) { if (recipe == null) { return(false); } using (var context = new CookBookContext()) { try { context.Entry(recipe).State = EntityState.Deleted; context.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine("Could not delete recipe"); Console.WriteLine(ex.Message); return(false); } } }
public bool AddIngredient(Ingredient ingredient) { if (ingredient == null) { return(false); } using (var context = new CookBookContext()) { try { context.Entry(ingredient).State = EntityState.Added; context.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine("Could not add new item"); Console.WriteLine(ex.Message); return(false); } } }
public bool AddMeasure(Measure measure) { if (measure == null) { return(false); } using (var context = new CookBookContext()) { try { context.Entry(measure).State = EntityState.Added; context.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine("Could not add new measure"); Console.WriteLine(ex.Message); return(false); } } }
public bool EditRecipeStep(RecipeStep step) { if (step == null) { return(false); } using (var context = new CookBookContext()) { try { context.Entry(step).State = EntityState.Modified; context.SaveChanges(); return(true); } catch (Exception ex) { Console.WriteLine("Could not edit Recipe Step"); Console.WriteLine(ex.Message); return(false); } } }