public void TestUpdateLastAppointment() { Appointment appt = new Appointment(); try { List <Appointment> apptList = AppointmentSchedulingServices.GetAllAppointments(); if (apptList != null && apptList.Count > 0) { appt = apptList[apptList.Count - 1]; appt.Comments = "Appointment updated"; appt.StartTime = DateTime.Now.AddDays(1); appt.EndTime = DateTime.Now.AddDays(1).AddMinutes(30); bool result = AppointmentSchedulingServices.UpdateAppointment(appt); Assert.IsTrue(result, "Appointment updated."); } else { Assert.Fail("Appointment List was Empty"); } } catch (AssertFailedException) { throw; } catch (Exception ex) { Assert.Fail("Exception thrown --> " + ex.ToString()); } }
/// <summary> /// The UpdateAppointment operation maps to HTTP POST method for modifying existing appointments. /// </summary> /// <param name="appointment">The updated appointment object</param> /// <returns>Success flag and Error message</returns> public ApiResponse UpdateAppointment(AppointmentContract appointment) { Appointment appt; bool success = false; ApiResponse response = new ApiResponse(); try { if (!(String.IsNullOrEmpty(appointment.FirstName) || String.IsNullOrEmpty(appointment.LastName) || String.IsNullOrEmpty(appointment.StartTime) || String.IsNullOrEmpty(appointment.EndTime) || String.IsNullOrEmpty(appointment.ID))) { appt = AppointmentSvc.getAppointmentModelType(appointment); if ((appt.StartTime > DateTime.Now) && (appt.StartTime <= appt.EndTime)) { if (appt.ID > 0) { success = AppointmentSchedulingServices.UpdateAppointment(appt); } else { response.ErrorMessage = "Missing identifier!"; } } else { response.ErrorMessage = "Please select a date in the future."; } } } catch (Exception e) { response.ErrorMessage = "Error updating appointment --> " + e.Message.ToString(); } finally { response.Success = success.ToString(); } return(response); }