public IHttpActionResult PutPost(int id, Post post) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != post.Id) { return BadRequest(); } db.Entry(post).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PostExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostPost(Post post) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.PostDbSet.Add(post); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = post.Id }, post); }