Commit a2caa1d7 authored by Vytor Calixto's avatar Vytor Calixto 👾
Browse files

Retorno das operações (sucesso, erro). Closes #11

parent 9734aebb
......@@ -15,6 +15,14 @@ class ContaBancariaController extends Controller{
$this->contaBancariaDao = new ContaBancariaDao(\FrameworkMvc\Dao\Conexao::getInstance());
$this->hydrator = new Hydrator();
}
public function indexAction(){
$contasBancarias = $this->contaBancariaDao->recuperar();
$viewData = array();
$viewData['contasBancarias'] = $contasBancarias;
$viewData['hydrator'] = $this->hydrator;
return $viewData;
}
public function createAction(){
$contaBancaria = new ContaBancaria();
......@@ -23,7 +31,13 @@ class ContaBancariaController extends Controller{
if(!empty($_POST)){
$contaBancaria = $this->hydrator->hydrate($_POST, $contaBancaria);
$result = $this->contaBancariaDao->inserir($contaBancaria);
($result > 0) ? ($viewData['success'] = true) : ($viewData['success'] = false);
if($result > 0) {
$viewData['success'] = true;
header("location:?module=contaBancaria&controller=contaBancaria&action=index&success=create");
}else{
$viewData['success'] = false;
}
}
$viewData['contaBancaria'] = $contaBancaria;
$viewData['hydrator'] = $this->hydrator;
......@@ -38,8 +52,14 @@ class ContaBancariaController extends Controller{
if(!empty($result)){
$contaBancaria = $result[0];
if(!empty($_POST)){
$this->hydrator->hydrate($_POST, $contaBancaria);
$contaBancaria = $this->hydrator->hydrate($_POST, $contaBancaria);
$result = $this->contaBancariaDao->atualizar($contaBancaria, array("id"=>$contaBancaria->getId()));
if($result > 0){
$viewData['success'] = true;
header("location:?module=contaBancaria&controller=contaBancaria&action=index&success=update");
}else{
$viewData['success'] = false;
}
}
}
}
......@@ -49,14 +69,6 @@ class ContaBancariaController extends Controller{
return $viewData;
}
public function indexAction(){
$contasBancarias = $this->contaBancariaDao->recuperar();
$viewData = array();
$viewData['contasBancarias'] = $contasBancarias;
$viewData['hydrator'] = $this->hydrator;
return $viewData;
}
public function deleteAction(){
$viewData = array();
......
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Index - RU</title>
</head>
<body>
<h1>Página Inicial</h1>
<ul>
<li><a href="?module=contaBancaria&controller=contaBancaria&action=create">Nova Conta Bancária</a></li>
</ul>
<fieldset>
<legend> Contas Bancárias </legend>
<table border ='1'>
<thead>
<tr>
<th>Agência</th>
<th>Número</th>
<th colspan="2">Ação</th>
</tr>
</thead>
<?php
foreach ($this->data['contasBancarias'] as $conta)
{
?>
<tr>
<th><?php echo $conta->getAgencia()?></th>
<th><?php echo $conta->getNumeroConta().'-'.$conta->getDigitoConta()?></th>
<th><a href='?module=contaBancaria&controller=contaBancaria&action=update&id=<?php echo $conta->getId()?>'>edit</a></th>
<th><a href='?module=contaBancaria&controller=contaBancaria&action=delete&id=<?php echo $conta->getId()?>'>delete</a></th>
</tr>
<?php
}
?>
</table>
</fieldset>
</body>
</html>
<?php
if(isset($_GET['success'])){
if ($_GET['success'] == 'delete')
echo 'Deletado com Sucesso';
if ($_GET['success'] == 'create')
echo 'Cadastrado com Sucesso';
if ($_GET['success'] == 'update')
echo 'Atualizado com Sucesso';
if ($_GET['success'] == 'notdelete')
echo 'Erro ao Deletar.';
if ($_GET['success'] == 'notcreate')
echo 'Erro ao Inserir';
if ($_GET['success'] == 'notupdate')
echo 'Erro ao Atualizar';
}
?>
<h1>Conta Bancária</h1>
<ul>
<li><a href="?module=contaBancaria&controller=contaBancaria&action=create">Nova Conta Bancária</a></li>
</ul>
<fieldset>
<legend> Contas Bancárias </legend>
<table border ='1'>
<thead>
<tr>
<th>Agência</th>
<th>Número</th>
<th colspan="2">Ação</th>
</tr>
</thead>
<?php
foreach ($this->data['contasBancarias'] as $conta){
?>
<tr>
<th><?php echo $conta->getAgencia()?></th>
<th><?php echo $conta->getNumeroConta().'-'.$conta->getDigitoConta()?></th>
<th><a href='?module=contaBancaria&controller=contaBancaria&action=update&id=<?php echo $conta->getId()?>'>edit</a></th>
<th><a href='?module=contaBancaria&controller=contaBancaria&action=delete&id=<?php echo $conta->getId()?>'>delete</a></th>
</tr>
<?php
}
?>
</table>
</fieldset>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment