public function create()
 {
     $descricoes = $this->request->getPost('descricao');
     $nomes = $this->request->getPost('nomes');
     $id_projeto = $this->request->getPost('projeto_id');
     $anexo_ids = [];
     foreach ($this->request->getUploadedFiles() as $i => $file) {
         $anexo = new Anexo();
         $anexo->setDescricao($descricoes[$i]);
         $anexo->setNome($nomes[$i]);
         $anexo->setOriginal($file->getName());
         $anexo->setCaminho(UPLOAD_PATH);
         if (!$anexo->validation() || !$anexo->save()) {
             throw new \Exception(PostResponse::createModelErrorMessages($anexo), StatusCodes::ERRO_CLI);
         }
         $novoNome = UPLOAD_PATH . "anexo_" . $anexo->getId() . "." . $file->getExtension();
         $anexo->setCaminho($novoNome);
         $anexo->save();
         $projeto_anexo = new ProjetoAnexos();
         $projeto_anexo->setIdAnexo($anexo->getId());
         $projeto_anexo->setIdProjeto($id_projeto);
         if (!$projeto_anexo->save()) {
             throw new \Exception(PostResponse::createModelErrorMessages($projeto_anexo), StatusCodes::ERRO_CLI);
         }
         $anexo_ids[] = $anexo->getId();
         $file->moveTo($novoNome);
     }
     return PostResponse::createResponse(true, count($anexo_ids) . " anexos adicionados com sucesso");
 }
 public function delete($id)
 {
     $cliente = Cliente::findFirst($id);
     if ($cliente) {
         if ($cliente->delete()) {
             return PostResponse::createResponse(PostResponse::STATUS_OK, "Cliente removido com sucesso");
         } else {
             throw new \Exception(PostResponse::createModelErrorMessages($cliente), StatusCodes::ERRO_CLI_CONFLICT);
         }
     } else {
         throw new \Exception("Cliente #{$id} não encontrado", StatusCodes::NAO_ENCONTRADO);
     }
 }
 public function update($id)
 {
     $projeto = Projeto::findFirst($id);
     if ($projeto) {
         $projeto->deleteRelated();
         $projeto = $this->createProjetoFromJsonRawData($projeto);
         if ($projeto->validation() && $projeto->save()) {
             return PostResponse::createResponse(PostResponse::STATUS_OK, "Projeto [#{$projeto->getId()} {$projeto->getNome()}] alterado com sucesso.");
         } else {
             throw new \Exception(PostResponse::createModelErrorMessages($projeto), StatusCodes::ERRO_CLI);
         }
     } else {
         throw new \Exception("Projeto #{$id} não encontrado", StatusCodes::NAO_ENCONTRADO);
     }
 }
 public function createTarefaItens(Tarefa $tarefa, $dataPost)
 {
     foreach ($dataPost->add_itens as $postItem) {
         $item = new TarefaItens();
         $item->setDescricao($postItem->descricao);
         $item->setPorcentagem($postItem->porcentagem);
         $item->setTitulo($postItem->titulo);
         $item->setStatus(TarefaItens::STATUS_NAO_CONCLUIDO);
         $item->setIdTarefa($tarefa->getId());
         if (!$item->validation() || !$item->save()) {
             $this->db->rollback();
             throw new \Exception(PostResponse::createModelErrorMessages($item), StatusCodes::ERRO_CLI);
         }
     }
     return true;
 }