public async Task<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 { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostCategory(Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Categories.Add(category); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = category.Id }, category); }