public IHttpActionResult PutRecipe(int id, Recipe recipe) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != recipe.RecipeId) { return(BadRequest()); } db.SetModified(recipe); try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!RecipeExists(id)) { return(NotFound()); } else { return(BadRequest("The data you are trying to save is older than the data in the database. Please refresh.")); } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Create([Bind(Include = "RecipeId,Source,Instructions,RowVersion,Title,Category")] Recipe recipe) { if (ModelState.IsValid) { db.Recipes.Add(recipe); db.SaveChanges(); return(RedirectToAction("Index")); } return(View("Create", recipe)); }
public IHttpActionResult PostRecipeNote(RecipeNote recipeNote) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.RecipeNotes.Add(recipeNote); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = recipeNote.RecipeNoteId }, recipeNote)); }