public function actionDelete($id, $type = null, $dropDown = false)
 {
     // Find Model
     $model = CategoryService::findById($id);
     // Delete/Render if exist
     if (isset($model)) {
         $model->type = $type;
         if ($model->load(Yii::$app->request->post(), 'Category') && $model->validate()) {
             $categoryOptions = OptionService::findByCategoryId($id);
             if (isset($categoryOptions)) {
                 foreach ($categoryOptions as $option) {
                     try {
                         OptionService::delete($option);
                     } catch (Exception $e) {
                         throw new HttpException(409, Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_DEPENDENCY));
                     }
                 }
             }
             if (CategoryService::delete($model, $avatar)) {
                 return $this->redirect($this->returnUrl);
             }
         }
         $avatar = $model->avatar;
         return $this->render('@cmsgears/module-core/admin/views/category/delete', ['model' => $model, 'avatar' => $model->avatar, 'dropDown' => $dropDown]);
     }
     // Model not found
     throw new NotFoundHttpException(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_NOT_FOUND));
 }
 public function actionAll($id)
 {
     Url::remember(["all?id={$id}"], 'options');
     $dataProvider = OptionService::getPagination(['conditions' => ['categoryId' => $id]]);
     $category = CategoryService::findById($id);
     return $this->render('@cmsgears/module-core/admin/views/category/option/all', ['dataProvider' => $dataProvider, 'category' => $category]);
 }
 public function actionDelete($id)
 {
     // Find Model
     $model = CategoryService::findById($id);
     if (isset($_POST) && count($_POST) > 0) {
         if (CategoryService::delete($model)) {
             return AjaxUtil::generateSuccess(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::MESSAGE_REQUEST), $model);
         }
     } else {
         // Generate Errors
         $errors = AjaxUtil::generateErrorMessage($model);
         // Trigger Ajax Failure
         return AjaxUtil::generateFailure(Yii::$app->cmgCoreMessage->getMessage(CoreGlobal::ERROR_REQUEST), $errors);
     }
 }