/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new ParamValue();
     if (isset($_POST['ParamValue'])) {
         $model->attributes = $_POST['ParamValue'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionBlank($id)
 {
     $event = Event::model()->findByPk($id);
     if (Yii::app()->request->isAjaxRequest) {
         $data = Yii::app()->request->getParam('data');
         $reg = new Reg();
         $reg->user_id = Yii::app()->user->getId();
         $reg->event_id = $event->id;
         try {
             if (!$reg->save()) {
                 throw new CHttpException(500, 'Internal server error.');
             }
             foreach ($data as $key => $value) {
                 $param_value = new ParamValue();
                 $param_value->param_id = $value["id"];
                 $param_value->reg_id = $reg->id;
                 $param_value->value = $value["value"];
                 if (!$param_value->save()) {
                     // @todo Откат всех инсертов.
                     throw new CHttpException(500, 'Internal server error.');
                 }
             }
             echo CJSON::encode(array('code' => 200));
             Yii::app()->end();
         } catch (CDbException $error) {
             throw new CHttpException(400, 'You are already registered for this event.');
         }
     }
     $reg = Reg::model()->findByAttributes(array('user_id' => Yii::app()->user->getId(), 'event_id' => $id));
     if ($reg !== null) {
         $this->redirect(array('user/blank', 'userId' => Yii::app()->user->getId(), 'eventId' => $id));
         Yii::app()->end();
     }
     $this->render('blank', array('event' => $event));
 }