@param Request $request
@param int $id

@return JsonResponse

@Route("/users/{id}", name="save_user", requirements={"id": "\d+"})
@Route("/users", name="save_new_user")
@Method({"PUT", "POST", "PATCH"})
504834
public function saveAction(Request $request, $id = null)
    {
        // check access
        if (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            throw $this->createAccessDeniedException();
        }

        // create command
        if (empty($id)) {
            // check permission
            if (!$this->isGranted('ROLE_USER_MANAGER')) {
                throw new AccessDeniedHttpException('Not allowed to insert user');
            }
            // create user instance
            $user = new User();
            // create command
            $command = new CreateUserCommand($user);
        } else {
            // find user
            $user = $this->getDoctrine()->getRepository('UserBundle:User')->find($id);
            if (empty($user)) {
                throw new NotFoundHttpException('User not found');
            }
            // check permissions
            if (!$this->isGranted(UserVoter::PERMISSION_EDIT, $user)) {
                throw new AccessDeniedHttpException('Not allowed to update user');
            }
            // create command
            $command = new UpdateUserCommand($user);
        }

        // set user params to handle
        $email = $request->get('email');
        if ($email) {
            $command->setEmail($email);
        }

        $password = $request->get('password');
        if ($password) {
            $command->setPassword($password);
        }

        $name = $request->get('name');
        if ($name) {
            $command->setName($name);
        }

        $roles = $request->get('roles');
        if (is_array($roles)) {
            $command->setRoles($roles);
        }

        $groups = $request->get('groups');
        if (is_array($groups)) {
            $command->setGroups($request->get('groups'));
        }

        $attributeValues = $request->get('attributeValues');
        if ($attributeValues) {
            $command->setAttributeValues($request->get('attributeValues'));
        }

        // handle command
        try {
            $this->get('user.command_bus')->handle($command);
        } catch (InvalidCommandException $e) {
            return new JsonResponse(
                [
                    'validation' => $this
                        ->get('user.validation_errors_converter')
                        ->constraintViolationListToArray($e->getConstraintViolationList())
                ],
                JsonResponse::HTTP_BAD_REQUEST
            );
        } catch(\Exception $e) {
            return new JsonResponse(
                [
                    'message'       => $e->getMessage(),
                ],
                JsonResponse::HTTP_INTERNAL_SERVER_ERROR
            );
        }

        // show success response
        return new JsonResponse([
            'id' => $user->getId(),
        ]);
    }
175753
public function addUsersAction($id, $class, Request $request)
    {
        $object = $this->find($class, $id);
        $users = $this->decodeIdsString($request, 'Claroline\CoreBundle\Entity\User');
        $this->crud->patch($object, 'user', Crud::COLLECTION_ADD, $users);

        return new JsonResponse(
            $this->serializer->serialize($object)
        );
    }
1134711
public function update(Request $request, $id)
    {
        $this->validate(
            $request,
            [
                'name' => 'required',
                'email' => 'required|string|max:255|email|unique:users,email,' . $id,
                'roles' => 'required'
            ]
        );

        $data = $request->except('password');
        if ($request->has('password')) {
            $data['password'] = bcrypt($request->password);
        }

        $user = User::findOrFail($id);
        $user->update($data);

        $user->roles()->detach();
        foreach ($request->roles as $role) {
            $user->assignRole($role);
        }

        return redirect('admin/users')->with('flash_message', 'User updated!');
    }
1311562
public function putAction(Request $request, $id)
    {
        $document = $this->findDocument($id, $this->getLocale($request));

        $this->requestHashChecker->checkHash($request, $document, $document->getUuid());
        if (!$this->checkAreaSnippet($request, $document)) {
            return new JsonResponse(
                [
                    'structures' => [],
                    'other' => [],
                    'isDefault' => true,
                ],
                409
            );
        }

        $this->processForm($request, $document);

        return $this->handleView($document);
    }
1187545
public function update(Request $request, $id)
    {
        if ($request->input('action') == 'update_account') {
            try {
                $this->userRepositoryInterface->update($request->all(), $id);
            } catch (FormValidationException $e) {
                Flash::error($e->getMessage());

                return redirect()
                  ->route('account.edit')
                  ->withErrors($e->getErrors())
                  ->withInput();
            } catch (UsersException $e) {
                Flash::error($e->getMessage());

                return redirect()->route('dashboard.index');
            }

            Flash::success(trans('dashboard::dashboard.flash.account.success'));

            return redirect()->route('account.edit');
        }

        if ($request->input('action') == 'change_password') {
            try {
                $this->userRepositoryInterface->updatePassword($request->all());
            } catch (FormValidationException $e) {
                Flash::error($e->getMessage());

                return redirect()
                  ->route('account.edit')
                  ->withErrors($e->getErrors());
            } catch (AuthenticationException $e) {
                Flash::error(trans('dashboard::dashboard.flash.password.fail'));

                return redirect()
                  ->route('account.edit');
            }

            Flash::success(trans('dashboard::dashboard.flash.password.success'));

            return redirect()->route('account.edit');
        }
    }
376614
public function update(Request $request, $id)
    {
        $this->validate(request(), [
            'name' => 'required|min:3|max:15',
            'email' => 'required|email',
            'password' => 'required|min:4'
        ]);

        $user = Admin::find($id);
        $user->name = request('name');
        $user->email = request('email');
        $user->password = bcrypt(request('password'));
        $user->save();

        session()->flash('success', 'Usuario actualizado con éxito!');
        return redirect()->route('usuarios.index');
    }
1307234
public function update(Update $request, $id)
    {
        try {
            $article = $this->repository->findById($id);

            $data = $request->all();

            unset($data['image']);
            unset($data['type']);

            if (\Input::hasFile('image')) {
                $article->deleteImage();

                $this->uploader->upload('image')->save('images/articles');

                $data['image'] = $this->uploader->getFilename();
            }

            $data['user_id'] = \Auth::id();
            $data['slug'] = Str::slug($data['title']);
            $article->update($data);

            return $this->redirect(isOnPages() ? 'pages.index' : 'articles.index');
        } catch (ModelNotFoundException $e) {
            return $this->redirectNotFound();
        }
    }
325927
public function update(Request $request, $id = null)
    {
        // validate data
        $validator = Validator::make($request->all(), [
            'name'         => 'sometimes|required|string|max:255|unique:permissions,name,'.$id,
            'display_name' => 'string|max:255',
            'description'  => 'max:1000'
        ]);

        if ($validator->fails()) {
            return response()->json(arrayView('phpsoft.users::errors/validation', [
                'errors' => $validator->errors()
            ]), 400);
        }

        // check permission
        $permission = Permission::find($id);

        if (!$permission) {
            return response()->json(null, 404);
        }

        // update permission
        $updatePermission = $permission->update($request->all());

        if (!$updatePermission) {
            return response()->json(null, 500); // @codeCoverageIgnore
        }

        return response()->json(arrayView('phpsoft.users::permission/read', [
            'permission' => $permission
        ]), 200);
    }
493853
public function putAction(Request $request, $id)
    {
        try {
            $order = $this->getManager()->save(
                $request->request->all(),
                $this->getLocaleManager()->retrieveLocale($this->getUser(), $request->get('locale')),
                $this->getUser()->getId(),
                $id
            );

            $view = $this->view($order, 200);
        } catch (OrderNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 404);
        } catch (OrderDependencyNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 400);
        } catch (MissingOrderAttributeException $exc) {
            $exception = new MissingArgumentException($this->getOrderEntityName(), $exc->getAttribute());
            $view = $this->view($exception->toArray(), 400);
        } catch (OrderException $exc) {
            $exception = new RestException($exc->getMessage());
            $view = $this->view($exception->toArray(), 400);
        }

        return $this->handleView($view);
    }
1370484
public function update(Request $request, $id)
    {
        $response = $this->repository->update($id, $request->all());
        return Response::apiResponse([
            'data' => $response
        ]);

    }
151997
public function update(Request $request, $id = null)
    {
        // validate
        $this->registerValidators();

        // check auth if update me
        if (!$id && !$this->checkAuth()) {
            return response()->json(null, 401);
        }

        // check user
        $user = $id ? AppUser::find($id) : Auth::user();

        if (!$user) {
            return response()->json(null, 404);
        }

        $request->id = $id;
        // validate data
        $validator = Validator::make($request->all(), [
            'name'         => 'sometimes|required|max:255',
            'email'        => 'sometimes|required|email|max:255|unique:users,email,'.$user->id,
            'old_password' => 'sometimes|required|changePassword|min:6',
            'password'     => 'sometimes|required|changePassword|confirmed|min:6',
            'username'     => 'string|max:30',
            'country'      => 'string|max:100',
            'location'     => 'string|max:100',
            'biography'    => 'string|max:255',
            'occupation'   => 'string|max:255',
            'website'      => 'string|max:255',
            'image'        => 'string|max:255',
            'gender'       => 'integer',
            'birthday'     => 'date'
        ]);

        if ($validator->fails()) {
            return response()->json(arrayView('phpsoft.users::errors/validation', [
                'errors' => $validator->errors()
            ]), 400);
        }

        // Update profile
        $user = $user->update($request->all());

        if (!$user) {
            return response()->json(null, 500); // @codeCoverageIgnore
        }

        return response()->json(arrayView('phpsoft.users::user/read', [
            'user' => $user
        ]), 200);
    }
86142
public function putAction(Request $request, $id)
    {
        try {
            $order = $this->getManager()->save(
                $request->request->all(),
                $this->getLocale($request),
                $this->getUser()->getId(),
                $id
            );

            $view = $this->view($order, 200);
        } catch (OrderNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 404);
        } catch (OrderDependencyNotFoundException $exc) {
            $exception = new EntityNotFoundException($exc->getEntityName(), $exc->getId());
            $view = $this->view($exception->toArray(), 400);
        } catch (MissingOrderAttributeException $exc) {
            $exception = new MissingArgumentException(self::$orderEntityName, $exc->getAttribute());
            $view = $this->view($exception->toArray(), 400);
        } catch (OrderException $exc) {
            $exception = new RestException($exc->getMessage());
            $view = $this->view($exception->toArray(), 400);
        }

        return $this->handleView($view);
    }
550047
public function updateAction(Request $request, $id)
    {
        $title = $request->get('title');
        $rawCriteria = json_decode($request->get('criteria'), true);

        $filterManager = $this->get('phlexible_message.filter_manager');

        $filter = $filterManager->find($id);
        $filter->setTitle($title);

        $criteria = new Criteria();
        $criteria->setMode(Criteria::MODE_OR);
        foreach ($rawCriteria as $group) {
            $criteriaGroup = new Criteria();
            $criteriaGroup->setMode(Criteria::MODE_AND);
            foreach ($group as $row) {
                if (!strlen($row['value'])) {
                    continue;
                }

                $criterium = new Criterium($row['key'], $row['value']);
                $criteriaGroup->add($criterium);
            }
            if ($criteriaGroup->count()) {
                $criteria->addCriteria($criteriaGroup);
            }
        }
        $filter->setCriteria($criteria);

        $filterManager->updateFilter($filter);

        return new ResultResponse(true, 'Filter updated');
    }
379018
public function update($id, Request $request)
    {
        return $this->updateModel($this->model()->find($id), $request->all(), 'edit');
    }
1236237
public function update(Request $request, $id)
    {
        $abstract = sprintf('themosis.metabox.%s', $id);

        try {
            $metabox = $this->manager->saveFields(app($abstract), $request);
        } catch (\Exception $exception) {
            return response()->json([
                'message' => $exception->getMessage(),
                'errors' => true
            ], 500);
        }

        return response()->json($metabox->toArray());
    }
215990
public function putAction($id, Request $request)
    {
        try {
            $contact = $this->getContactManager()->save(
                $request->request->all(),
                $id
            );

            $apiContact = $this->getContactManager()->getContact($contact, $this->getUser()->getLocale());
            $view = $this->view($apiContact, 200);
            $context = new Context();
            $context->setGroups(static::$contactSerializationGroups);
            $view->setContext($context);
        } catch (EntityNotFoundException $exc) {
            $view = $this->view($exc->toArray(), 404);
        } catch (RestException $exc) {
            $view = $this->view($exc->toArray(), 400);
        }

        return $this->handleView($view);
    }
1067826
protected function handleWriteUser($request, $id = null)
    {
        $user = $id ? $this->getUser($id) : null;

        $form = $this->formFactory->createNamed(null, 'sonata_user_api_form_user', $user, [
            'csrf_protection' => false,
        ]);

        $form->handleRequest($request);

        if ($form->isValid()) {
            $user = $form->getData();
            $this->userManager->updateUser($user);

            $context = new Context();
            $context->setGroups(['sonata_api_read']);
            $context->enableMaxDepth();

            $view = FOSRestView::create($user);
            $view->setContext($context);

            return $view;
        }

        return $form;
    }