public async Task<IHttpActionResult> PutBlog(int id, Blog blog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != blog.BlogId) { return BadRequest(); } db.Entry(blog).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BlogExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostBlog(Blog blog) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Blogs.Add(blog); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = blog.BlogId }, blog); }