private static IEnumerable <SlotDTO> SplitDayIntoChunks(Workinghours wh, List <Reservation> rlist, Speciality speciality) { var slotList = new List <SlotDTO>(); var specialityVisitDurationMinutes = Convert.ToInt32(speciality.DurationOfVisit); if (rlist.Count > 0) { rlist = rlist.OrderBy(x => x.Starttime).ToList(); //podziel na sloty, okres między początkiem pracy, a pierwszą wizytą slotList = SplitChunkIntoSlots(wh.From, rlist.First().Starttime, specialityVisitDurationMinutes); for (int i = 0; i < (rlist.Count - 1); i++) { //podziel na sloty, okres między końcem i-tej wizyty, a początkiem (i+1)-szej wizyty slotList.AddRange(SplitChunkIntoSlots(rlist.ElementAt(i).Endtime, rlist.ElementAt(i + 1).Starttime, specialityVisitDurationMinutes)); } //podziel na sloty, okres między końcem ostatniej wizyty, a końcem dnia pracy slotList.AddRange(SplitChunkIntoSlots(rlist.Last().Endtime, wh.To, specialityVisitDurationMinutes)); } else { //gdy nie ma wizyt tego dnia, podziel cały dzień na sloty slotList.AddRange(SplitChunkIntoSlots(wh.From, wh.To, specialityVisitDurationMinutes)); } return(slotList); }
public async Task <IActionResult> PutWorkinghours(decimal id, Workinghours workhours) { if (id != workhours.Id) { return(BadRequest(BadRequestEmptyJsonResult)); } if (IsDoctorAccessingElsesData(workhours.DoctorId)) { return(Unauthorized(UnauthorizedEmptyJsonResult)); } if (await _reservationsRepository.IsAnyReservationScheduledThatDay(workhours.LocalId, workhours.DoctorId, workhours.From, workhours.To)) { return(BadRequest(BadRequestJsonResult("During these work hours, there's already an appointment reserved"))); } if (!WorkinghoursExists(id)) { return(NotFound(NotFoundEmptyJsonResult)); } try { _repository.Update(workhours); _repository.Save(); } catch (DbUpdateConcurrencyException e) { return(StatusCode(500, InternalServerErrorJsonResult(e.Message))); } return(Ok(OkEmptyJsonResult)); }
public async Task <bool> BeOnAWorkDay(Reservation res, IRoomsRepository roomRepo) { Room room = roomRepo.GetByID(res.RoomId); Workinghours wh = await _workHoursRepository.GetByDetails(res.DoctorId, room.LocalId, res.Starttime.Date); return(wh != null && wh.From <= res.Starttime && wh.To >= res.Endtime); }
public async Task <ActionResult <Workinghours> > PostWorkinghours(Workinghours workinghours) { if (IsDoctorAccessingElsesData(workinghours.DoctorId)) { return(Unauthorized(UnauthorizedEmptyJsonResult)); } workinghours.Id = Decimal.Zero; try { _repository.Insert(workinghours); _repository.Save(); } catch (DbUpdateException e) { return(StatusCode(500, InternalServerErrorJsonResult(e.Message))); } return(Created("", workinghours)); }
public async Task <bool> BeOnAWorkDay(ReservationDTO res) { Workinghours wh = await _workHoursRepository.GetByDetails(res.DoctorId, res.LocalId, res.Starttime.Date); return(wh != null && wh.From <= res.Starttime && wh.To >= res.Endtime); }