public ActionResult Create(Appointment appointment) { if (ModelState.IsValid) { appointmentRepository.InsertOrUpdate(appointment); appointmentRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
// PUT /api/appointmentapi/5 public HttpResponseMessage Put(int id, Appointment value) { if (ModelState.IsValid) { _appointmentRepository.InsertOrUpdate(value); _appointmentRepository.Save(); return new HttpResponseMessage(HttpStatusCode.NoContent); } throw new HttpResponseException(HttpStatusCode.BadRequest); }
public void InsertOrUpdate(Appointment appointment) { if (appointment.Id == default(int)) { // New entity context.Appointments.Add(appointment); } else { // Existing entity context.Entry(appointment).State = EntityState.Modified; } }
// POST /api/appointmentapi public HttpResponseMessage Post(Appointment value) { if (ModelState.IsValid) { _appointmentRepository.InsertOrUpdate(value); _appointmentRepository.Save(); //Created! //var response = new HttpResponseMessage<Appointment>(value, HttpStatusCode.Created); var response = Request.CreateResponse<Appointment>(HttpStatusCode.Created, value); //Let them know where the new appointment is string uri = Url.Route(null, new { id = value.Id }); response.Headers.Location = new Uri(Request.RequestUri, uri); return response; } throw new HttpResponseException(HttpStatusCode.BadRequest); }
public void InsertOrUpdate(Appointment appointment) { throw new NotImplementedException(); }