public async Task<IHttpActionResult> PostIngredient(Ingredient ingredient) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Ingredient.Add(ingredient); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (IngredientExists(ingredient.Name)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = ingredient.Name }, ingredient); }
public async Task<IHttpActionResult> PutIngredient(string id, Ingredient ingredient) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != ingredient.Name) { return BadRequest(); } db.Entry(ingredient).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!IngredientExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }