public IHttpActionResult PostPatient(Patient patient) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Patient.Add(patient); try { db.SaveChanges(); } catch (DbUpdateException) { if (PatientExists(patient.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = patient.Id }, patient); }
public IHttpActionResult PutPatient(int id, Patient patient) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != patient.Id) { return BadRequest(); } db.Entry(patient).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PatientExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }