/** * API Method inserts a new Endereco 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'); } $endereco = new Endereco($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 // $endereco->Id = $this->SafeGetVal($json, 'id'); $endereco->Logradouro = $this->SafeGetVal($json, 'logradouro'); $endereco->Numero = $this->SafeGetVal($json, 'numero'); $endereco->Complemento = $this->SafeGetVal($json, 'complemento'); $endereco->Cidade = $this->SafeGetVal($json, 'cidade'); $endereco->Uf = $this->SafeGetVal($json, 'uf'); $endereco->Cep = $this->SafeGetVal($json, 'cep'); $endereco->Cliente = $this->SafeGetVal($json, 'cliente'); $endereco->Validate(); $errors = $endereco->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Please check the form for errors', $errors); } else { $endereco->Save(); $this->RenderJSON($endereco, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }