public IHttpActionResult Postcategory(category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.categories.Add(category); try { db.SaveChanges(); } catch (DbUpdateException) { if (categoryExists(category.Label)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = category.Label }, category); }
public IHttpActionResult Putcategory(string id, category category) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != category.Label) { return BadRequest(); } db.Entry(category).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!categoryExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }