// GET: Appointments/Edit/5 public ActionResult Edit(int id) { string url = "AppointmentsData/GetAppointment/" + id; //sends http request and retrieves the response HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { UpdateViewAppointment viewModel = new UpdateViewAppointment(); Appointment appointment = response.Content.ReadAsAsync <Appointment>().Result; var cultureInfo = new CultureInfo("en-CA"); DateTime requestedDateTime = DateTime.Parse(appointment.RequestDatetime, cultureInfo); viewModel.RequestDatetime = requestedDateTime.ToString("yyyy/MM/dd HH:mm "); viewModel.PatientUser = new ApplicationDbContext().Users.Find(appointment.PatientID); viewModel.PhysicianUser = new ApplicationDbContext().Users.Find(appointment.PhysicianID); viewModel.Subject = appointment.Subject; viewModel.Message = appointment.Message; viewModel.Status = appointment.Status; viewModel.SentOn = appointment.SentOn; viewModel.PatientID = appointment.PatientID; viewModel.PhysicianID = appointment.PhysicianID; viewModel.ID = appointment.ID; return(View(viewModel)); } else { return(RedirectToAction("Error")); } }
public ActionResult Edit(int id, UpdateViewAppointment viewModel) { if (ModelState.IsValid) { Appointment appointment = new Appointment(); appointment.ID = viewModel.ID; appointment.PatientID = viewModel.PatientID; appointment.PhysicianID = viewModel.PhysicianID; appointment.SentOn = viewModel.SentOn; appointment.Subject = viewModel.Subject; appointment.Message = viewModel.Message; appointment.Status = viewModel.Status; //pass along authentication credential in http request GetApplicationCookie(); //update the appointment string url = "AppointmentsData/UpdateAppointment/" + id; var cultureInfo = new CultureInfo("en-CA"); DateTime requestedDateTime = DateTime.Parse(viewModel.RequestDatetime, cultureInfo); appointment.RequestDatetime = requestedDateTime.ToString("yyyy/MM/dd hh:mm tt"); HttpContent content = new StringContent(jss.Serialize(appointment)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.PostAsync(url, content).Result; if (response.IsSuccessStatusCode) { return(RedirectToAction("Details", new { id = id })); } else { return(RedirectToAction("Error")); } } else { return(View(viewModel)); } }