// POST api/UniversalCourse public HttpResponseMessage PostUniversalCourse(UniversalCourse universalcourse) { if (ModelState.IsValid) { db.UniversalCourses.Add(universalcourse); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, universalcourse); response.Headers.Location = new Uri(Url.Link("UniversalCourses", new { code = universalcourse.Code })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/UniversalCourse/5 public HttpResponseMessage PutUniversalCourse(string code, UniversalCourse universalcourse) { if (ModelState.IsValid && code == universalcourse.Code) { db.Entry(universalcourse).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }