/**
  * @param $lectureId
  * @param BreakInputModel $model
  * @return View
  * @throws \Exception
  * @Validatetoken('token')
  * @Method('GET', 'POST')
  * @Route('lectures/{integer $lectureId}/addbreak')
  */
 public function addBreak(BreakInputModel $model, integer $lectureId)
 {
     if (!$model->isValid()) {
         return new View('Lectures', 'addbreak', $model);
     }
     $service = new LecturesService($this->dbContext);
     if (HttpContext::getInstance()->isPost()) {
         $response = $service->addBreak($model);
         if ($response->hasError()) {
             if ($response->getErrorCode() > 1) {
                 throw new \Exception($response->getMessage(), $response->getErrorCode());
             } else {
                 $this->addErrorMessage($response->getMessage());
                 $this->redirectToUrl('/conferences/details/' . $response->getModel());
             }
         } else {
             $this->addInfoMessage($response->getMessage());
             $this->redirectToUrl('/conferences/details/' . $response->getModel());
         }
     } else {
         $conferenceId = $this->dbContext->getLecturesRepository()->filterById(" = {$lectureId}")->findOne()->getConferenceId();
         $lecture = $this->dbContext->getLecturesRepository()->filterById(" = {$lectureId}")->findOne();
         $breakModel = new BreakInputModel();
         $breakModel->setLectureId($lectureId);
         $breakModel->setStartDate($lecture->getStartDate());
         $breakModel->setEndDate($lecture->getEndDate());
         $breakModel->setConferenceId($conferenceId);
         return new View('Lectures', 'addbreak', $breakModel);
     }
 }
 public function addBreak(BreakInputModel $model) : ServiceResponse
 {
     $lectureId = $model->getLectureId();
     $lecture = $this->dbContext->getLecturesRepository()->filterById(" = {$lectureId}")->findOne();
     if ($lecture->getId() == null) {
         return new ServiceResponse(404, "Lecture not found.");
     }
     $breakStartDate = strtotime($model->getStartDate());
     $breakEndDate = strtotime($model->getEndDate());
     if ($breakStartDate >= $breakEndDate) {
         return new ServiceResponse(1, "Start date/time cannot be later than End date/time.", $model->getConferenceId());
     }
     $lectureModel = new LectureViewModel($lecture);
     if (!$this->contains($lectureModel, $model)) {
         return new ServiceResponse(1, "Break failed to add. Time is outside lecture time.", $model->getConferenceId());
     }
     $lectureBreaks = $this->dbContext->getLectureBreaksRepository()->filterByLectureId(" = {$lectureId}")->findAll();
     $conferenceId = $model->getConferenceId();
     foreach ($lectureBreaks->getLectureBreaks() as $break) {
         $otherBreakModel = new AddBreakViewModel($break);
         if ($this->compareTo($model, $otherBreakModel) == 0) {
             return new ServiceResponse(1, "Break failed to add. Timing conflicts with another break.", $model->getConferenceId());
         }
     }
     $break = new LectureBreak($model->getTitle(), $model->getDescription(), $model->getLectureId(), $model->getStartDate(), $model->getEndDate());
     $this->dbContext->getLectureBreaksRepository()->add($break);
     $this->dbContext->saveChanges();
     return new ServiceResponse(null, "Break added.", $model->getConferenceId());
 }