public ActionResult Create(Attendee attendee) { if (ModelState.IsValid) { db.Attendees.Add(attendee); db.SaveChanges(); return RedirectToAction("Index"); } return View(attendee); }
// POST api/AttendeesSvc public HttpResponseMessage PostAttendee(Attendee attendee) { if (ModelState.IsValid) { db.Attendees.Add(attendee); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, attendee); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = attendee.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/AttendeesSvc/5 public HttpResponseMessage PutAttendee(int id, Attendee attendee) { if (ModelState.IsValid && id == attendee.Id) { db.Entry(attendee).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(Attendee attendee) { if (ModelState.IsValid) { db.Entry(attendee).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(attendee); }