/** * API Method inserts a new Certificado record and render response as JSON */ public function Create() { // Requer permissão de acesso $this->RequirePermission(Usuario::$P_ADMIN, 'SecureExample.LoginForm', 'Autentique-se para acessar esta página', 'Você não possui permissão para acessar essa página ou sua sessão expirou'); try { $json = json_decode(RequestUtil::GetBody()); if (!$json) { throw new Exception('The request body does not contain valid JSON'); } $certificado = new Certificado($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 // $certificado->IdCertificado = $this->SafeGetVal($json, 'idCertificado'); $certificado->DataEmissao = date('Y-m-d H:i:s', strtotime($this->SafeGetVal($json, 'dataEmissao'))); $certificado->Livro = $this->SafeGetVal($json, 'livro'); $certificado->Folha = $this->SafeGetVal($json, 'folha'); $certificado->Codigo = $this->SafeGetVal($json, 'codigo'); $certificado->IdUsuario = $this->SafeGetVal($json, 'idUsuario'); $certificado->Validate(); $errors = $certificado->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Verifique erros no preenchimento do formulário', $errors); } else { $certificado->Save(); $this->RenderJSON($certificado, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }