public ActionResult Create(Survey survey) { if (ModelState.IsValid) { db.Surveys.Add(survey); db.SaveChanges(); return RedirectToAction("Index"); } return View(survey); }
// POST api/Survey public HttpResponseMessage PostSurvey(Survey survey) { if (ModelState.IsValid) { db.Surveys.Add(survey); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, survey); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = survey.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Survey/5 public HttpResponseMessage PutSurvey(int id, Survey survey) { if (ModelState.IsValid && id == survey.Id) { db.Entry(survey).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public ActionResult Edit(Survey survey) { if (ModelState.IsValid) { db.Entry(survey).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(survey); }