/**
  * Processes the form.
  *
  * @param User $user
  * @param array         $parameters
  * @param String        $method
  *
  * @return User Entity
  *
  * @throws ElasticaClient\UserBundle\Exception\InvalidFormException
  */
 private function processForm(User $user, $parameters, $method = 'PUT')
 {
     $form = $this->formFactory->create(new UserType(), $user, array('method' => $method));
     $form->submit($parameters);
     if ($form->isValid()) {
         $user = $form->getData();
         if ($userResponse = $this->getByEmail($user->getEmail())) {
             if ($method == 'POST') {
                 throw new UserExistException('This User Exist', 'user-exist');
             } else {
                 if ($user->getId() == $userResponse->getId()) {
                     $this->userService->deleteUser($user->getId());
                     $this->userService->addUser($user);
                     return $user;
                 } else {
                     throw new UserExistException('This User Exist', 'user-exist');
                 }
             }
         } else {
             $userId = $this->userService->addUser($user);
             $user->setId($userId);
             return $user;
         }
     }
     throw new InvalidFormException('Invalid submitted data', $form);
 }
 /**
  * Gets user by email
  * 
  * @param string $userEmail
  * @return User
  */
 public function getUserByEmail($userEmail)
 {
     return $this->userService->getByEmail($userEmail);
 }