public IHttpActionResult PostStepsPerDay(StepsPerDay stepsPerDay) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Patient patient = db.Patients.Find(stepsPerDay.PatientId); if (patient == null) { return BadRequest("Patient with id " + stepsPerDay.PatientId + " does not exist."); } db.StepsPerDays.Add(stepsPerDay); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new {controller = "stepsperdays", id = stepsPerDay.StepsPerDayId}, stepsPerDay); }
public IHttpActionResult PutStepsPerDay(int id, StepsPerDay stepsPerDays) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != stepsPerDays.StepsPerDayId) { return BadRequest("The StepsPerDayId in the URL and the StepsPerDayId in the data do not match."); } Patient patient = db.Patients.Find(stepsPerDays.PatientId); if (patient == null) { return BadRequest("Patient with id " + stepsPerDays.PatientId + " does not exist."); } db.Entry(stepsPerDays).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StepsPerDaysExists(id)) { return BadRequest("StepsPerDay with id " + id + " does not exist."); } else { throw; } } return CreatedAtRoute("DefaultApi", new {controller = "stepsperdays", id = stepsPerDays.StepsPerDayId}, stepsPerDays); }