public IHttpActionResult PutCourse(int id, Course course) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != course.CourseID) { return BadRequest(); } db.Entry(course).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostCourse(Course course) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Courses.Add(course); try { db.SaveChanges(); } catch (DbUpdateException) { if (CourseExists(course.CourseID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = course.CourseID }, course); }
public IHttpActionResult PostCourse(Course course) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Courses.Add(course); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = course.CourseID }, course); }