// POST api/Courses public HttpResponseMessage PostCourse(Course course) { if (ModelState.IsValid) { courseRepository.Create(course); var response = Request.CreateResponse(HttpStatusCode.Created, course); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = course.Id })); return response; } return Request.CreateResponse(HttpStatusCode.BadRequest); }
// PUT api/Courses/5 public HttpResponseMessage PutCourse(int id, Course course) { if (ModelState.IsValid && id == course.Id) { try { courseRepository.Update(course); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } return Request.CreateResponse(HttpStatusCode.BadRequest); }