Example #1
0
 /**
  * @return HttpResult
  */
 public function insert()
 {
     $returnResult = new HttpResult();
     $retornoDaPaginaHTML = new HttpAdminGenericResult();
     $senha = DataHandler::getValueByArrayIndex($_POST, "password");
     $confirm_password = DataHandler::getValueByArrayIndex($_POST, "confirm_password");
     $VO = new UserDetailVO($_POST);
     if ($senha != NULL) {
         if ($senha == NULL || $senha != $confirm_password) {
             $ReturnResultVO = new ReturnResultVO();
             $ReturnResultVO->success = FALSE;
             $ReturnResultVO->addMessage("confimação de senha incorreta");
         } else {
             $VO->setActive(1);
             $VO->setUserTypeId(1);
             $ReturnResultVO = $VO->commit(TRUE);
             if ($ReturnResultVO->success) {
                 $user_id = $ReturnResultVO->result;
                 //cadastra o endereço principal
                 $AddressVO = new AddressVO($_POST);
                 //$AddressVO->setStateId($_POST["state_id"]);
                 $tempReturnResultVO = $AddressVO->commit(TRUE);
                 //print_r($tempReturnDataVO);
                 //se cadastrou atualiza o user datail com o id do address cadastrado
                 //se não apaga o user datail e user
                 if ($tempReturnResultVO->success) {
                     $address_id = $tempReturnResultVO->result;
                     $VO->setId($user_id, TRUE);
                     $VO->setAddressId($address_id);
                     $ReturnResultVO = $VO->commit();
                     if ($ReturnResultVO->success) {
                         $UserAddressVO = new UserAddressVO();
                         $UserAddressVO->setAddressId($address_id);
                         $UserAddressVO->setUserId($user_id);
                         $UserAddressVO->setActive(1);
                         $ReturnResultUserAddress = $UserAddressVO->commit();
                     } else {
                         //apaga o usuario e o os detalhes do usuario
                         $UserDetailDAO = UserDetailDAO::getInstance();
                         $UserDetailDAO->delete($user_id);
                         //apaga o endereco
                         $AddressDAO = new AddressDAO();
                         $AddressDAO->delete($address_id);
                     }
                 } else {
                     $ReturnResultVO = $tempReturnResultVO;
                     //apaga o usuario e o os detalhes do usuario
                     $UserDetailDAO = UserDetailDAO::getInstance();
                     $UserDetailDAO->delete($user_id);
                 }
             }
         }
         if ($ReturnResultVO->success) {
             Navigation::redirect("admin/user");
             exit;
         }
         $retornoDaPaginaHTML->return_result_vo = $ReturnResultVO;
     }
     $retornoDaPaginaHTML->user_detail_vo = $VO;
     //iniciando o retorno padrao em http result
     $returnResult->setHttpContentResult($retornoDaPaginaHTML);
     return $returnResult;
 }