/**
  * Shows the view to create (edit) engine
  */
 public function assignAction()
 {
     $id = $this->dispatcher->getParams()[0];
     // check "edit" or "new" action in use
     $engine = $id === null ? new Engines() : Engines::findFirst($id);
     if (!$engine instanceof Engines) {
         return $this->response->redirect(['for' => 'dashboard-full', 'controller' => $this->router->getControllerName(), 'action' => $this->router->getActionName()]);
     }
     try {
         // handling POST data
         if ($this->request->isPost()) {
             $engines = $engine->setName($this->request->getPost('name'))->setDescription($this->request->getPost('description'), null, '')->setHost($this->request->getPost('host'))->setCode($this->request->getPost('code'))->setCurrencyId($this->request->getPost('currency_id', null, 1))->setStatus($this->request->getPost('status', null, 0));
             if (!$engines->save()) {
                 // the store failed, the following message were produced
                 foreach ($engines->getMessages() as $message) {
                     $this->flashSession->error((string) $message);
                 }
                 // forward does not working correctly with this  action type
                 // by the way this handle need to remove in another action (
                 return $this->response->redirect(['for' => 'dashboard-full', 'controller' => $this->router->getControllerName(), 'action' => $this->router->getActionName()]);
             } else {
                 // saved successfully
                 if (!isset($id)) {
                     $this->flashSession->success('The engine was successfully added!');
                 } else {
                     $this->flashSession->success('The engine was successfully updated!');
                 }
                 if ($this->_logger) {
                     $this->_logger->log('Engine assigned by ' . $this->request->getClientAddress());
                 }
                 // forward does not working correctly with this  action type
                 // by the way this handle need to remove in another action (
                 return $this->response->redirect(['for' => 'dashboard-full', 'controller' => $this->router->getControllerName()]);
             }
         }
         // build meta data
         $title = !isset($id) ? 'Add' : 'Edit';
         $this->tag->prependTitle($title . ' - ' . self::NAME);
         // add crumb to chain (name, link)
         $this->_breadcrumbs->add(self::NAME, $this->url->get(['for' => 'dashboard-controller', 'controller' => 'engines']))->add($title);
         // set variables output to view
         $this->view->setVars(['title' => $title, 'form' => new Forms\EngineForm(null, ['currency' => Currency::find(), 'default' => isset($id) ? $engine : null])]);
     } catch (\Phalcon\Exception $e) {
         echo $e->getMessage();
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCurrency()
 {
     return $this->hasOne(Currency::className(), ['id' => 'currency_id']);
 }