public async Task<IHttpActionResult> PutModel(int id, Model model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != model.Id) { return BadRequest(); } db.Entry(model).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ModelExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostModel(Model model) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Models.Add(model); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = model.Id }, model); }