public IHttpActionResult PostPostCategory(PostCategory postCategory) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.PostCategories.Add(postCategory); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = postCategory.Id }, postCategory); }
public IHttpActionResult PutPostCategory(int id, PostCategory postCategory) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != postCategory.Id) { return BadRequest(); } db.Entry(postCategory).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PostCategoryExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }