/**
  * 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)
 {
     $file_Path = Yii::getPathOfAlias('webroot.attachments.sewadars_images');
     $model = $this->loadModel($id);
     $old_pic = $model->sewardar_picture;
     if ($model->is_technical) {
         $technical = SewadardTechnicalDetail::model()->find('sewadar_id=:user_id', array(':user_id' => $model->sewadar_id));
     } else {
         $technical = new SewadardTechnicalDetail();
     }
     if ($technical === null) {
         $technical = new SewadardTechnicalDetail();
     }
     $basic = new basic();
     $age = $basic->getAgeRange();
     $area = $basic->getAreas();
     $sections = $basic->getSewadarSections();
     $bloodGroup = basic::getBloodGroup();
     // $this->performAjaxValidation($model);
     if (isset($_POST['Sewadars'])) {
         $model->attributes = $_POST['Sewadars'];
         $model->blood_group = $_POST['Sewadars']['blood_group'];
         if ($_FILES['Sewadars']['name']['sewardar_picture'] != '') {
             $model->sewardar_picture = CUploadedFile::getInstance($model, 'sewardar_picture');
             $ext = pathinfo($model->sewardar_picture, PATHINFO_EXTENSION);
             $SName = basic::removeSpace($model->sewadar_name);
             $FileName = $model->badge_no . '_' . $SName . '.' . $ext;
             $saved = $model->sewardar_picture->saveAs($file_Path . '/' . $FileName);
             $model->sewardar_picture = $FileName;
         } else {
             if ($old_pic == '') {
                 $saved = true;
                 $model->sewardar_picture = '';
             } else {
                 $saved = true;
                 $model->sewardar_picture = $old_pic;
             }
         }
         if ($_POST['Sewadars']['is_technical'] == 1) {
             $technical->attributes = $_POST['SewadardTechnicalDetail'];
             $technical->department_company = $_POST['SewadardTechnicalDetail']['department_company'];
             $technical->period_from = $_POST['SewadardTechnicalDetail']['period_from'];
             $technical->period_to = $_POST['SewadardTechnicalDetail']['period_to'];
             $technical->sewadar_id = $model->sewadar_id;
         }
         if ($model->date_of_birth == '') {
             $model->date_of_birth = date('Y-m-d', strtotime("-{$model->age} years"));
         }
         if ($model->age == '') {
             $datetime1 = new DateTime($model->date_of_birth);
             $datetime2 = new DateTime(date('Y-m-d'));
             $interval = $datetime1->diff($datetime2);
             $model->age = $interval->format('%y');
         }
         if ($model->validate()) {
             if ($model->save()) {
                 if ($saved) {
                     if ($_POST['Sewadars']['is_technical'] == 1) {
                         $technicalModel = SewadardTechnicalDetail::model()->findByPk($technical->detail_id);
                         $technicalModel->attributes = $_POST['SewadardTechnicalDetail'];
                         $technicalModel->department_company = $_POST['SewadardTechnicalDetail']['department_company'];
                         $technicalModel->period_from = $_POST['SewadardTechnicalDetail']['period_from'];
                         $technicalModel->period_to = $_POST['SewadardTechnicalDetail']['period_to'];
                         $technicalModel->sewadar_id = $model->sewadar_id;
                         $technicalModel->save();
                     }
                     Yii::app()->user->setFlash('success', 'Record Inserted Successfully.');
                 } else {
                     Yii::app()->user->setFlash('error', 'error while uploading file.');
                 }
             }
             $this->refresh();
         }
     }
     $this->render('update', array('model' => $model, 'technical' => $technical, 'age' => $age, 'area' => $area, 'sections' => $sections, 'bloodGroup' => $bloodGroup));
 }