/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ModulePermission'])) {
         $model = new ModulePermission();
         $model->attributes = $_POST['ModulePermission'];
         $model->created_id = $this->user_data['user_id'];
         $model->updated_id = $this->user_data['user_id'];
         $model->user_role_type = $id;
         $flag = 0;
         if (isset($_POST['ModulePermission']['module_id']) && !empty($_POST['ModulePermission']['module_id'])) {
             $moudule_list = $_POST['ModulePermission']['module_id'];
             ModulePermission::model()->deleteAll("user_role_type ='" . $id . "'");
         }
         foreach ($moudule_list as $row) {
             $model->setIsNewRecord(true);
             $model->module_id = $row;
             $model->insert();
             $model->module_permission_id = $model->module_permission_id + 1;
             $flag = 1;
         }
         Yii::app()->user->setFlash('type', 'success');
         Yii::app()->user->setFlash('message', 'Permission Updated successfully.');
         if ($flag) {
             $this->redirect(array('index'));
         }
     }
     $this->render('update', array('model' => $model));
 }