/** * @param identfier * @return the messages */ public function delete($id) { $response = new Response(); $entity = UserRepository::getById($id); $errMsg = UserRepository::delete($id); if ($errMsg) { throw new CustomException($errMsg, Constants::errorCode()['BadRequest']); } else { $response->messages[] = new Message(null, Constants::getMessageType()['Success'], String::format(CommonResources::getMessage('Msg_SuccessfullyDeleted'), CommonResources::getMessage('User'), $entity->name)); } return $response; }
/** * @param id */ public static function delete($id) { try { $manager = new TransactionManager(); $transaction = $manager->get(); $model = self::getModel(); $entity = $model::findFirst($id); $entity->setTransaction($transaction); if ($entity->delete() == false) { $transaction->rollback($entity->getMessages()[0]->message); } $transaction->commit(); return $entity->getMessages(); } catch (Phalcon\Mvc\Model\Transaction\Failed $e) { throw new CustomException($model->getMessages(), Constants::errorCode()['InternalServerError']); } catch (\Exception $e) { if (!empty($entity->getMessages())) { throw new CustomException($entity->getMessages(), Constants::errorCode()['InternalServerError']); } else { var_dump($e->getMessage()); throw $e; } } }