public static bool DeleteAppointment(int apptId) { var dc = new AppointmentsDBEntities(); bool success = false; try { var apptmnt = (from appt in dc.Appointments where appt.ID == apptId select appt).FirstOrDefault <Appointment>(); if (apptmnt != null) { dc.Appointments.Remove(apptmnt); success = 0 < dc.SaveChanges(); } else { throw new RecordNotFoundException("Record not found!"); } } catch (Exception) { throw; } return(success); }
public static bool UpdateAppointment(Appointment appointment) { var dc = new AppointmentsDBEntities(); bool success = false; try { if (isScheduleRangeValid(appointment.StartTime, appointment.EndTime, appointment.ID)) { var apptmnt = (from appt in dc.Appointments where appt.ID == appointment.ID select appt).FirstOrDefault <Appointment>(); if (apptmnt != null) { apptmnt.FirstName = appointment.FirstName; apptmnt.LastName = appointment.LastName; apptmnt.StartTime = appointment.StartTime; apptmnt.EndTime = appointment.EndTime; apptmnt.Comments = appointment.Comments; success = 0 < dc.SaveChanges(); } else { throw new RecordNotFoundException("Record not found!"); } } else { throw new InvalidRangeException("Invalid range!"); } } catch (Exception) { throw; } return(success); }
public static bool AddAppointment(Appointment appointment) { var dc = new AppointmentsDBEntities(); bool success = false; try { if (isScheduleRangeValid(appointment.StartTime, appointment.EndTime, null)) { dc.Appointments.Add(appointment); success = 0 < dc.SaveChanges(); } else { throw new InvalidRangeException("Invalid range!"); } } catch (Exception) { throw; } return(success); }