getContainer()->getPermissionsService()->currentUserCanWrite(Entities::EVENTS)) { throw new AccessDeniedException('You are not allowed to add event'); } $result = new CommandResult(); $this->checkMandatoryFields($command); /** @var EventRepository $eventRepository */ $eventRepository = $this->container->get('domain.booking.event.repository'); /** @var EventApplicationService $eventApplicationService */ $eventApplicationService = $this->container->get('application.booking.event.service'); $eventRepository->beginTransaction(); $event = EventFactory::create($command->getFields()); if (!$event instanceof Event) { $result->setResult(CommandResult::RESULT_ERROR); $result->setMessage('Could not delete event'); return $result; } try { $events = $eventApplicationService->add($event); } catch (QueryExecutionException $e) { $eventRepository->rollback(); throw $e; } $eventRepository->commit(); $result->setResult(CommandResult::RESULT_SUCCESS); $result->setMessage('Successfully added new event.'); $result->setData( [ Entities::EVENTS => $events->toArray(), ] ); return $result; } }