public function updateAction() { $request = $this->getRequest(); $recipe = $this->readService->findById($this->params('id')); if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) { throw new UnauthorizedException('Insufficient Permissions'); } $viewModel = new ViewModel(); $viewModel->setTemplate('recipe/update'); $viewModel->setVariables(['form' => $this->form]); $this->form->bind($recipe); if ($request->isPost()) { $this->form->setData($request->getPost()); if ($this->form->isValid()) { try { $this->writeService->save($this->form->getData()); $this->flashMessenger()->addSuccessMessage('Rezept erfolgreich aktualisiert'); $this->redirect()->toRoute('recipe/read/update', ['id' => $this->params('id')]); } catch (\Exception $e) { var_dump($e->getMessage()); } } } $this->layout('layout/backend'); return $viewModel; }
public function deleteAction() { $request = $this->getRequest(); $recipe = $this->readService->findById($this->params('id')); if (false === $this->authorizationService->isGranted('recipe.manage', $recipe)) { throw new UnauthorizedException('Insufficient Permissions'); } $viewModel = new ViewModel(); $viewModel->setTemplate('recipe/delete'); $viewModel->setVariables(['recipe' => $recipe, 'form' => $this->form]); if ($request->isPost()) { $this->form->setData($request->getPost()); if ($this->form->isValid()) { try { $this->writeService->delete($recipe); $this->flashMessenger()->addSuccessMessage('Rezept wurde erfolgreich gelöscht!'); return $this->redirect()->toRoute('recipe'); } catch (\Exception $e) { var_dump($e->getMessage()); } } } return $viewModel; }
public function createAction() { if (false === $this->authorizationService->isGranted('recipe.add')) { throw new UnauthorizedException('Insufficient Permissions'); } $viewModel = new ViewModel(); $viewModel->setTemplate('recipe/add'); $viewModel->setVariables(['form' => $this->form]); $request = $this->getRequest(); if ($request->isPost()) { $this->form->setData($request->getPost()); if ($this->form->isValid()) { try { $recipe = $this->form->getData(); $this->writeService->save($recipe); return $this->redirect()->toRoute('recipe/read', ['id' => $recipe->getId()]); } catch (\Exception $e) { var_dump($e->getMessage()); } } } $this->layout('layout/backend'); return $viewModel; }