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