public IHttpActionResult PostOperator(Operator @operator) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.ops.Add(@operator); try { db.SaveChanges(); } catch (DbUpdateException) { if (OperatorExists(@operator.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = @operator.Id }, @operator); }
public IHttpActionResult PutOperator(int id, Operator @operator) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != @operator.Id) { return BadRequest(); } db.Entry(@operator).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OperatorExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }