[HttpGet("{userId}")] //Done public ActionResult <Doctor> GetmyInfo(int userId) { try { Doctor infoDoc = doctorDAO.GetmyInfo(userId); if (infoDoc == null) { return(NoContent()); } return(Ok(infoDoc)); } catch (Exception) { return(StatusCode(500)); } }
[HttpPost("requestAppointment")] //done public ActionResult <Appointment> CreateAppointmentRequest(Appointment appointment) { try { DayOfWeek day = appointment.Date.DayOfWeek; string dayString = Convert.ToString(day); Doctor doctor = doctorDAO.GetmyInfo(appointment.DoctorId); TimeSpan appointmentTime = new TimeSpan(0, 30, 0); bool isWorking = false; if (dayString == "Monday") { int startvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Monday.Start, appointment.Time); int endvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Monday.End, appointment.Time.Add(appointmentTime)); isWorking = startvsAptTime <= 0 && endvsAptTime >= 0; if (isWorking) { appointment.OfficeId = doctor.WeeklyHours.Monday.OfficeOfDay.OfficeId; } } else if (dayString == "Tuesday") { int startvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Tuesday.Start, appointment.Time); int endvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Tuesday.End, appointment.Time.Add(appointmentTime)); isWorking = startvsAptTime <= 0 && endvsAptTime >= 0; if (isWorking) { appointment.OfficeId = doctor.WeeklyHours.Tuesday.OfficeOfDay.OfficeId; } } else if (dayString == "Wednesday") { int startvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Wednesday.Start, appointment.Time); int endvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Wednesday.End, appointment.Time.Add(appointmentTime)); isWorking = startvsAptTime <= 0 && endvsAptTime >= 0; if (isWorking) { appointment.OfficeId = doctor.WeeklyHours.Wednesday.OfficeOfDay.OfficeId; } } else if (dayString == "Thursday") { int startvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Thursday.Start, appointment.Time); int endvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Thursday.End, appointment.Time.Add(appointmentTime)); isWorking = startvsAptTime <= 0 && endvsAptTime >= 0; if (isWorking) { appointment.OfficeId = doctor.WeeklyHours.Thursday.OfficeOfDay.OfficeId; } } else if (dayString == "Friday") { int startvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Friday.Start, appointment.Time); int endvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Friday.End, appointment.Time.Add(appointmentTime)); isWorking = startvsAptTime <= 0 && endvsAptTime >= 0; if (isWorking) { appointment.OfficeId = doctor.WeeklyHours.Friday.OfficeOfDay.OfficeId; } } else if (dayString == "Saturday") { int startvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Saturday.Start, appointment.Time); int endvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Saturday.End, appointment.Time.Add(appointmentTime)); isWorking = startvsAptTime <= 0 && endvsAptTime >= 0; if (isWorking) { appointment.OfficeId = doctor.WeeklyHours.Saturday.OfficeOfDay.OfficeId; } } else { int startvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Sunday.Start, appointment.Time); int endvsAptTime = TimeSpan.Compare(doctor.WeeklyHours.Sunday.End, appointment.Time.Add(appointmentTime)); isWorking = startvsAptTime <= 0 && endvsAptTime >= 0; if (isWorking) { appointment.OfficeId = doctor.WeeklyHours.Sunday.OfficeOfDay.OfficeId; } } if (isWorking) { List <Appointment> docAppts = appointmentDAO.GetAppointmentsByDoctor(appointment.DoctorId); bool isAvailable = true; foreach (Appointment a in docAppts) { if ((a.Date.Date == appointment.Date.Date && a.Time >= appointment.Time && a.Time < appointment.Time.Add(appointmentTime)) || (a.Date.Date == appointment.Date.Date && a.Time.Add(appointmentTime) > appointment.Time && a.Time.Add(appointmentTime) <= appointment.Time.Add(appointmentTime))) { isAvailable = false; } } if (isAvailable) { Appointment newAppt = appointmentDAO.CreateAppointmentRequest(appointment); return(Ok(newAppt)); } else { return(Conflict()); } } else { return(Conflict()); } } catch (Exception e) { Console.WriteLine(e.Message); return(StatusCode(500)); } }