//Create Method public static void Create(AppointmentModel appointment) { if (!IsProviderAvailable(appointment)) { throw new Exception("The selected service provider is not available for an appointment at this time."); } if (!IsClientAvailable(appointment)) { throw new Exception("The selected customer already has an appointment booked at this time."); } appointment.Id = Interlocked.Increment(ref appointmentCounter); appointment.Provider = ServiceProviderRepository.Read(appointment.Provider.Id); appointment.Client = CustomerRepository.Read(appointment.Client.Id); _appointments.Add(appointment); }
//Update Method public static void Update(int id, AppointmentModel appointment) { if (!IsProviderAvailable(appointment)) { throw new Exception("The selected service provider is not available for an appointment at this time."); } if (!IsClientAvailable(appointment)) { throw new Exception("The selected customer already has an appointment booked at this time."); } var index = _appointments.FindIndex(x => x.Id == id); _appointments.RemoveAt(index); appointment.Id = id; appointment.Provider = ServiceProviderRepository.Read(appointment.Provider.Id); appointment.Client = CustomerRepository.Read(appointment.Client.Id); _appointments.Insert(index, appointment); }