public IHttpActionResult PostDoctor(DoctorModel doctor) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbDoctor = new Doctor(); dbDoctor.Update(doctor); db.Doctors.Add(dbDoctor); try { db.SaveChanges(); } catch (Exception) { throw new Exception("Unable to add the doctor to the database"); } doctor.DoctorID = dbDoctor.DoctorID; return CreatedAtRoute("DefaultApi", new { id = doctor.DoctorID }, doctor); }
/// <summary> /// Finds an exam room based on a doctors preference - or the next available exam room. /// </summary> /// <param name="doctor"></param> /// <returns></returns> private ExamRoom examRoomDoctorMatcher(Doctor doctor) { var currentCheckin = db.DoctorChecks.ToList() .Where(dc => dc.DoctorID == doctor.DoctorID && !dc.CheckoutDateTime.HasValue) .LastOrDefault(); // If no checkin records found, look for any exam room if (currentCheckin == null) { return findAvailableExamRoom(); } else // Return the preferred exam room if it has no upcoming appointments { if (upcomingAppointmentsForExamRoom(currentCheckin.ExamRoomID) == 0) { return currentCheckin.ExamRoom; } else { // Find the exam room with the fewest upcoming appointments, // excluding the preferred exam room, but if no exam room found, // then search for any available exam room var examRoom = findAvailableExamRoomExclude(currentCheckin.ExamRoomID); if (examRoom != null) { return examRoom; } else { return findAvailableExamRoom(); } } } }