/** * API Method inserts a new Pedido 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'); } $pedido = new Pedido($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 // $pedido->Id = $this->SafeGetVal($json, 'id'); $pedido->Datacriacao = date('Y-m-d H:i:s', strtotime($this->SafeGetVal($json, 'datacriacao'))); $pedido->Observacao = $this->SafeGetVal($json, 'observacao'); $pedido->Dataentrega = date('Y-m-d H:i:s', strtotime($this->SafeGetVal($json, 'dataentrega'))); $pedido->Valorfrete = $this->SafeGetVal($json, 'valorfrete'); $pedido->Valordesconto = $this->SafeGetVal($json, 'valordesconto'); $pedido->Valortotal = $this->SafeGetVal($json, 'valortotal'); $pedido->Statuspedido = $this->SafeGetVal($json, 'statuspedido'); $pedido->Formapagamento = $this->SafeGetVal($json, 'formapagamento'); $pedido->Vendedor = $this->SafeGetVal($json, 'vendedor'); $pedido->Cliente = $this->SafeGetVal($json, 'cliente'); $pedido->Enderecoentrega = $this->SafeGetVal($json, 'enderecoentrega'); $pedido->Itempedido = $this->SafeGetVal($json, 'itempedido'); $pedido->Validate(); $errors = $pedido->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Please check the form for errors', $errors); } else { $pedido->Save(); $this->RenderJSON($pedido, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }
/** * API Method inserts a new Pedido 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'); } $pedido = new Pedido($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 // $pedido->Id = $this->SafeGetVal($json, 'id'); $pedido->ProdutoId = $this->SafeGetVal($json, 'produtoId'); $pedido->ClienteId = $this->SafeGetVal($json, 'clienteId'); $pedido->Validate(); $errors = $pedido->GetValidationErrors(); if (count($errors) > 0) { $this->RenderErrorJSON('Please check the form for errors', $errors); } else { $pedido->Save(); $this->RenderJSON($pedido, $this->JSONPCallback(), true, $this->SimpleObjectParams()); } } catch (Exception $ex) { $this->RenderExceptionJSON($ex); } }