public function addquestion($post)
 {
     $status = true;
     if (!Yii::app()->user->isGuest) {
         $role = Yii::app()->user->role;
         $userid = Yii::app()->user->getId();
     } else {
         $role = $post['q_role'];
         if ($role == 'homeowner') {
             $email = $post['q_hemail'];
             $count_email = Homeowners::model()->countByAttributes(array('email' => $email));
             if ($count_email > 0) {
                 $details = Homeowners::model()->findByAttributes(array('email' => $email));
                 $userid = $details->homeowner_id;
             } else {
                 $password = Yii::app()->Ini->generate_password();
                 $huser = new Homeowners();
                 $huser->firstname = $post['q_firstname'];
                 $huser->lastname = $post['q_lastname'];
                 $huser->email = $post['q_hemail'];
                 $huser->username = $post['q_husername'];
                 $huser->password = $password;
                 if ($huser->save()) {
                     Yii::app()->Ini->savetovnoc($email);
                     $userid = Yii::app()->db->getLastInsertId();
                     Yii::app()->Ini->savetoaffiliate($userid, 'homeowner');
                     $this->SendMailAfterSignUp($userid);
                 } else {
                     $status = false;
                     $return['message'] = $huser->getErrors();
                 }
             }
         } else {
             $email = $post['q_cemail'];
             $password = $post['q_password'];
             $count_email = Contractors::model()->countByAttributes(array('Email' => $email));
             if ($count_email > 0) {
                 $details = Contractors::model()->findByAttributes(array('Email' => $email));
                 $userid = $details->ContractorId;
             } else {
                 $cont = new Contractors();
                 $cont->Name = $post['q_company'];
                 $cont->ContactName = $post['q_contactname'];
                 $cont->Email = $post['q_cemail'];
                 $cont->Username = $post['q_cusername'];
                 $cont->Password = $post['q_password'];
                 if ($cont->save()) {
                     Yii::app()->Ini->savetovnoc($email);
                     $userid = Yii::app()->db->getLastInsertId();
                 } else {
                     $status = false;
                     $return['message'] = $cont->getErrors();
                 }
             }
         }
     }
     if ($status) {
         if (Yii::app()->user->isGuest) {
             $identity = new UserIdentity($email, $password, $role);
             if ($identity->authenticate()) {
                 Yii::app()->user->login($identity);
                 $owner_id = Yii::app()->user->getId();
                 Yii::app()->Ini->savetoaffiliate($owner_id, $role);
             }
         }
         $q = new Questions();
         $q->title = $post['q_title'];
         $q->content = $post['q_content'];
         $q->owner_id = $userid;
         $q->owner_user_type = $role;
         $q->project_type_id = $post['q_category'];
         if ($q->save()) {
             $return['url'] = 'questions/details/id/' . Yii::app()->db->getLastInsertId() . '/n/' . Yii::app()->Ini->slugstring($q->title);
         } else {
             $status = false;
             $return['message'] = $q->getErrors();
         }
     }
     $return['status'] = $status;
     $this->renderJSON($return, $status);
 }