public ActionResult Create(Course course) { if (ModelState.IsValid) { db.Courses.Add(course); db.SaveChanges(); return RedirectToAction("Index"); } return View(course); }
public ActionResult Edit(Course course) { if (ModelState.IsValid) { db.Entry(course).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(course); }
// PUT api/Course/5 public HttpResponseMessage PutCourse(string id, Course course) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != course.courseId) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(course).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/Course public HttpResponseMessage PostCourse(Course course) { if (ModelState.IsValid) { db.Courses.Add(course); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, course); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = course.courseId })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }