/**
  * {@inheritdoc}
  */
 public function move($categoryId, $parentId, $afterId = null)
 {
     $model = $this->categoryRepository->get($categoryId);
     $parentCategory = $this->categoryRepository->get($parentId);
     if ($parentCategory->hasChildren()) {
         $parentChildren = $parentCategory->getChildren();
         $categoryIds = explode(',', $parentChildren);
         $lastId = array_pop($categoryIds);
         $afterId = $afterId === null || $afterId > $lastId ? $lastId : $afterId;
     }
     if (strpos($parentCategory->getPath(), $model->getPath()) === 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Operation do not allow to move a parent category to any of children category'));
     }
     try {
         $model->move($parentId, $afterId);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Could not move category'));
     }
     return true;
 }