public IHttpActionResult PutMenuItem(int id, MenuItem menuItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != menuItem.ID) { return BadRequest(); } db.Entry(menuItem).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MenuItemExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostMenuItem(MenuItem menuItem) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.MenuItems.Add(menuItem); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = menuItem.ID }, menuItem); }