public function putAction($id, Request $request)
    {
        if (!$this->isGranted('IS_AUTHENTICATED_FULLY')) {
            throw new InsufficientAuthenticationException('You must be authenticated to view users');
        }

        $user = $this->getEntityManager()->find(get_class($this->getUser()), $id);

        if (!$user) {
            return $this->create404Response(sprintf('User not found with id %d', $id));
        }

        if (!$this->isGranted('EDIT', $user)) {
            throw new InsufficientAuthenticationException(sprintf('You are not authorized to view user with id %s', $id));
        }

        $user = $this->deserializeEntity($request->request->all(), $user);

        if ($request->request->has('password')) {
            $encoderFactory = $this->getContainer()->get('security.context')->getEncoderFactory();
            $password = $request->request->get('password', '');

            if ($encoderFactory && $encoder = $encoderFactory->getEncoder($user)) {
                $password = $encoder->encodePassword($password, '');
            }

            $user->setPassword($password);
        }

        $this->getEntityManager()->persist($user);
        $this->getEntityManager()->flush($user);

        return new Response("", 204);
    }