Ejemplo n.º 1
0
 /**
  * API Method inserts a new Imovel record and render response as JSON
  */
 public function Create()
 {
     try {
         $json = json_decode(RequestUtil::GetBody());
         if (!$json) {
             throw new Exception('The request body does not contain valid JSON');
         }
         $imovel = new Imovel($this->Phreezer);
         // TODO: any fields that should not be inserted by the user should be commented out
         // this is an auto-increment.  uncomment if updating is allowed
         // $imovel->Id = $this->SafeGetVal($json, 'id');
         $imovel->Titulo = $this->SafeGetVal($json, 'titulo');
         $imovel->Descricao = $this->SafeGetVal($json, 'descricao');
         $imovel->DataDisponibilidade = date('Y-m-d H:i:s', strtotime($this->SafeGetVal($json, 'dataDisponibilidade')));
         $imovel->Imagem = $this->SafeGetVal($json, 'imagem');
         $imovel->Valor = $this->SafeGetVal($json, 'valor');
         $imovel->EmailContato = $this->SafeGetVal($json, 'emailContato');
         $imovel->TelefoneContato = $this->SafeGetVal($json, 'telefoneContato');
         $imovel->TipoImovelId = $this->SafeGetVal($json, 'tipoImovelId');
         $imovel->Validate();
         $errors = $imovel->GetValidationErrors();
         if (count($errors) > 0) {
             $this->RenderErrorJSON('Por Favor, verifique os erros', $errors);
         } else {
             $imovel->Save();
             $this->RenderJSON($imovel, $this->JSONPCallback(), true, $this->SimpleObjectParams());
         }
     } catch (Exception $ex) {
         $this->RenderExceptionJSON($ex);
     }
 }