public async Task<IHttpActionResult> PostCategory(Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Category.Add(category); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (CategoryExists(category.SmallCategoryName)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = category.SmallCategoryName }, category); }
public async Task<IHttpActionResult> PutCategory(string id, Category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != category.SmallCategoryName) { 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); }