Example #1
0
 public function cadastrar()
 {
     try {
         if (empty($_POST['nome'])) {
             throw new \InvalidArgumentException("Favor preencher o nome do usuário");
         }
         if (empty($_POST['perfil'])) {
             throw new \InvalidArgumentException("Favor selecionar o perfil do usuárui");
         }
         if (empty($_POST['email'])) {
             throw new \InvalidArgumentException("Favor preencher o e-mail do usuário");
         }
         $perfil = new Perfil();
         $perfil->id = $_POST['perfil'];
         $perfil = $this->fachada->buscarPerfil($perfil);
         $usuario = new Usuario();
         $usuario->id = $_POST['id'];
         $usuario->nome = $_POST['nome'];
         $usuario->email = $_POST['email'];
         $usuario->ativo = !empty($_POST['ativo']);
         $usuario->perfil = $perfil;
         if (empty($usuario->id)) {
             $this->fachada->cadastrarUsuario($usuario);
         } else {
             $this->fachada->alterarUsuario($usuario);
         }
         echo new JSONResponse(true, self::MSG_OPERACAO_SUCESSO);
     } catch (\Exception $ex) {
         echo new JSONResponse(false, $ex->getMessage());
     }
 }
Example #2
0
 public function buscarPerfil()
 {
     try {
         $id = array_key_exists('id', $_POST) ? $_POST['id'] : null;
         if (empty($id)) {
             throw new \Exception("Selecione um perfil.");
         }
         $perfil = new Perfil();
         $perfil->id = $id;
         $perfil = $this->fachada->buscarPerfil($perfil);
         $perfil->permissoes = $perfil->permissoes->toArray();
         echo new JSONResponse(true, $perfil);
     } catch (\Exception $e) {
         echo new JSONResponse(false, $e->getMessage());
     }
 }