public IHttpActionResult PutFood(int id, Food food) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != food.Id) { return BadRequest(); } try { repository.EditFood(id, food); } catch (DbUpdateConcurrencyException) { if (!repository.FoodExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostFood(Food food) { if (!ModelState.IsValid) { return BadRequest(ModelState); } repository.AddFood(food); return CreatedAtRoute("DefaultApi", new { id = food.Id }, food); }