/**
  * Process the flow of creating a new user
  *
  * @return \Illuminate\Database\Eloquent\Model|mixed
  * @throws \Exception
  */
 protected function doCreate()
 {
     try {
         $this->repoWrapper->begin();
         $createdUser = $this->userRepo->createRaw($this->getUserData());
         $createdUser = $this->addCommandRolesToUser($createdUser);
         $createdUser = $this->addCommandCategoriesToUser($createdUser);
     } catch (\Exception $e) {
         $this->repoWrapper->failure();
         throw $e;
     }
     $this->repoWrapper->end();
     return $createdUser;
 }
 /**
  * Execute the console command.
  *
  * @throws ArtisanException
  * @return mixed
  */
 public function fire()
 {
     $this->repoWrapper->begin();
     try {
         $user = $this->createUser();
         $roles = ['admin', 'authenticated'];
         $this->addRolesToUser($user, $roles);
     } catch (RepositoryException $e) {
         $this->repoWrapper->failure();
         $this->error('Repository job roll backed');
         throw new ArtisanException($e->getMessage());
     }
     $this->repoWrapper->end();
     $this->info('User created successfully');
 }
 /**
  * Do Update
  *
  * @throws \Exception
  * @return User
  */
 protected function doUpdate()
 {
     // As we don't want to do incomplete jobs here
     // we wrap the repository code so we can trace it for rollbacking
     // In this case RepoWrapperInterface has been bound to a class
     // that uses database transactions fo this feature.
     $userData = $this->getUserData();
     // get data that fits user repository for update
     $userId = $userData['id'];
     unset($userData['id']);
     // unset user id because it is not in mass assignment of the model
     try {
         $this->repoWrapper->begin();
         $updated = $this->userRepo->updateById($userId, $userData);
         $updated = $this->addCommandRolesToUser($updated);
         $updated = $this->addCommandCategoriesToUser($updated);
     } catch (\Exception $e) {
         $this->repoWrapper->failure();
         throw $e;
     }
     $this->repoWrapper->end();
     return $updated;
 }
 /**
  * Create article with all dependencies
  *
  * @return Article
  * @throws \Exception
  */
 protected function doCreate()
 {
     try {
         $this->repoWrapper->begin();
         $this->checkArticleState();
         $this->checkArticleCategory();
         $this->created = $this->doArticleCreate();
         $this->addState();
         $this->addTags();
     } catch (\Exception $e) {
         $this->repoWrapper->failure();
         throw $e;
     }
     $this->repoWrapper->end();
     return $this->created;
 }