/// <summary> /// The DeleteAppointment operation maps to HTTP DELETE method for deleting appointments. /// </summary> /// <param name="id">The appointment id</param> /// <returns>Success flag and Error message</returns> public ApiResponse DeleteAppointment(string id) { int apptId; bool success = false; ApiResponse response = new ApiResponse(); try { if (!String.IsNullOrEmpty(id)) { Int32.TryParse(id, out apptId); if (apptId > 0) { success = AppointmentSchedulingServices.DeleteAppointment(apptId); } } } catch (Exception e) { response.ErrorMessage = "Error deleting appointment --> " + e.Message.ToString(); } finally { response.Success = success.ToString(); } return(response); }
public void TestCreateNewAppointmentInThePast() { Appointment appt = new Appointment(); try { appt.StartTime = DateTime.Now.AddDays(-1); appt.EndTime = DateTime.Now.AddDays(-1).AddMinutes(15); appt.FirstName = "John"; appt.LastName = "Doe"; appt.Comments = "Appointment Created"; bool result = AppointmentSchedulingServices.AddAppointment(appt); } catch (InvalidRangeException) { Assert.IsTrue(true, "Cannot create appointments in the past."); } catch (AssertFailedException) { throw; } catch (Exception ex) { Assert.Fail("Exception thrown --> " + ex.ToString()); } }
public void TestDeleteLastAppointment() { Appointment appt = new Appointment(); try { List <Appointment> apptList = AppointmentSchedulingServices.GetAllAppointments(); if (apptList != null && apptList.Count > 0) { appt = apptList[apptList.Count - 1]; bool result = AppointmentSchedulingServices.DeleteAppointment(appt.ID); Assert.IsTrue(result, "Appointment deleted."); } else { Assert.Fail("Appointment List was Empty"); } } catch (AssertFailedException) { throw; } catch (Exception ex) { Assert.Fail("Exception thrown --> " + ex.ToString()); } }
public void TestUpperOverlapOnAddAppointment() { Appointment appt = new Appointment(); try { List <Appointment> apptList = AppointmentSchedulingServices.GetAllAppointments(); if (apptList != null && apptList.Count > 0) { appt = apptList[apptList.Count - 1]; appt.StartTime = appt.StartTime.Value.AddMinutes(15); appt.EndTime = appt.EndTime.AddMinutes(15); bool result = AppointmentSchedulingServices.AddAppointment(appt); } else { Assert.Fail("Appointment List was Empty"); } } catch (AssertFailedException) { throw; } catch (InvalidRangeException) { Assert.IsTrue(true, "Invalid range expected."); } catch (Exception ex) { Assert.Fail("Exception thrown --> " + ex.ToString()); } }
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 ListAppointments operation maps to HTTP GET method for fetching appointments. /// </summary> /// <param name="startTime">Start time</param> /// <param name="endTime">End time</param> /// <returns>Success flag, error message and appointment list.</returns> public ApiResponse ListAppointments(String startTime, String endTime) { List <AppointmentContract> results = new List <AppointmentContract>(); List <Appointment> appts = null; ApiResponse response = new ApiResponse(); bool success = false; DateTime startDt; DateTime endDt; try { DateTime.TryParse(startTime, out startDt); DateTime.TryParse(endTime, out endDt); if (String.IsNullOrEmpty(startTime) && String.IsNullOrEmpty(endTime)) { appts = AppointmentSchedulingServices.GetAllAppointments(); } else if ((!String.IsNullOrEmpty(startTime) && !String.IsNullOrEmpty(endTime)) && (startDt != null && endDt != null) && (startDt <= endDt)) { appts = AppointmentSchedulingServices.GetAppointmentsByDateRange(startDt, endDt); } else { response.ErrorMessage = "Invalid filters"; } if (String.IsNullOrEmpty(response.ErrorMessage) && appts != null) { foreach (Appointment appt in appts) { AppointmentContract tmpApptmnt = new AppointmentContract(); tmpApptmnt.ID = appt.ID.ToString(); tmpApptmnt.StartTime = appt.StartTime.ToString(); tmpApptmnt.EndTime = appt.EndTime.ToString(); tmpApptmnt.FirstName = appt.FirstName; tmpApptmnt.LastName = appt.LastName; tmpApptmnt.Comments = appt.Comments; results.Add(tmpApptmnt); } success = true; } } catch (Exception e) { response.ErrorMessage = "Error listing appointments --> " + e.Message.ToString(); } finally { response.Success = success.ToString(); response.Appointments = (results.Count > 0) ? results : null; } return(response); }
/// <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); }
public void TestGetAppointmentsByRange() { List <Appointment> apptList; try { apptList = AppointmentSchedulingServices.GetAppointmentsByDateRange(new DateTime(2015, 01, 01), new DateTime(2015, 12, 31)); Assert.IsNotNull(apptList, "Appointment list not null."); Assert.IsTrue(apptList.Count > 0, "One or more elements found this year."); } catch (AssertFailedException) { throw; } catch (Exception ex) { Assert.Fail("Exception thrown --> " + ex.ToString()); } }