public Appointment MakeAppointment(int doctorId, int patientId, DateTime date, string hour, string comment) { Patient patient = database.Patients.Find(patientId); Doctor doctor = database.Doctors.Find(doctorId); if (!doctorService.IsSlotStringValid(hour)) { return(null); } int slot = SlotHelper.HourToSlot(hour); if (!doctorService.IsSlotAvailable(doctor, date, slot)) { return(null); } Appointment appointment = new Appointment(); appointment.Doctor = doctor; appointment.Patient = patient; appointment.Date = date; appointment.StartSlot = slot; appointment.EndSlot = slot; appointment.Comment = comment; appointment.RoomNumber = 555; database.Appointments.Add(appointment); database.SaveChanges(); return(appointment); }
public void HourToSlot_Full_Day_Slots_Should_Equal_DateTime_Reference() { // Arrange // 1 int = 15 minute slot; 96 slots = 24h const int slotCount = 96; string[] fullDayDateTimeReference = new string[slotCount]; int[] fullDaySlots = new int[slotCount]; for (int i = 0; i < slotCount; i++) { fullDayDateTimeReference[i] = DateTime.Now.Date.AddMinutes(i * 15).ToString("HH:mm"); } // Act for (int i = 0; i < slotCount; i++) { fullDaySlots[i] = SlotHelper.HourToSlot(fullDayDateTimeReference[i]); } // Assert for (int i = 0; i < slotCount; i++) { Assert.Equal(fullDaySlots[i], i); } }
protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); var doctors = new[] { new { Id = 1, Name = "Dr", Surname = "Etker", Specialization = "Kisiele", Text = "Very good doctor" }, new { Id = 2, Name = "Dr", Surname = "Pepper", Specialization = "Drinking", Text = "Not so good doctor" }, new { Id = 3, Name = "Dr", Surname = "Dre", Specialization = "Wrapping", Text = "Quite good doctor." } }; var workingHours = new[] { new { Id = 1, Date = new DateTime(2019, 11, 11), // Monday StartSlot = SlotHelper.HourToSlot("8:00"), EndSlot = SlotHelper.HourToSlot("16:00"), DoctorId = doctors[0].Id, }, new { Id = 2, Date = new DateTime(2019, 11, 13), // Wednesday StartSlot = SlotHelper.HourToSlot("7:30"), EndSlot = SlotHelper.HourToSlot("15:30"), DoctorId = doctors[0].Id, }, new { Id = 3, Date = new DateTime(2019, 11, 13), // Wednesday StartSlot = SlotHelper.HourToSlot("6:30"), EndSlot = SlotHelper.HourToSlot("14:30"), DoctorId = doctors[1].Id, } }; modelBuilder.Entity <Doctor>().HasData(doctors); modelBuilder.Entity <WorkingHours>().HasData(workingHours); base.OnModelCreating(modelBuilder); }