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); }
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); }