Create record

@param HCCityRequest $request
@return JsonResponse
@throws \Throwable
500479
public function store(HCCityRequest $request): JsonResponse
    {
        $this->connection->beginTransaction();

        try {
            /** @var HCCity $record */
            $record = $this->service->getRepository()->create($request->getRecordData());
            $record->updateTranslations($request->getTranslations());

            $this->connection->commit();
        } catch (\Throwable $e) {
            $this->connection->rollBack();

            return $this->response->error($e->getMessage());
        }

        event(new HCCityCreated($record));

        if ($request->isResponseForOptions()) {

            return $this->response->success("Created", $this->service->getRepository()->formatForOptions($record));
        } else {

            return $this->response->success("Created");
        }
    }
782541
public function getOptions(HCResourceGrabPropertyRequest $request): JsonResponse
      {
          return response()->json(
              $this->service->getRepository()->getOptions($request)
          );
      }
293562
protected function crudCreate(Request $request = null)
    {
        try{
            
            $entity = $this->getEntity();
            $form = $this->createAndBindForm($request, $this->getEntityType() , $entity);
            $page = static::NEW_VIEW;
            
            if ($form->isValid()) {
                $this->saveEntity($entity);                
                if($request->get('_loop_create')){
                    $form = $this->createForm($this->getEntityType(), $this->getEntity());
                }else{
                    $page = static::SHOW_VIEW;
                    $form = $this->createDeleteForm($entity->getId());
                }
                $form = $form->createView();
                return $this->render($page, $this->commonsResponseVars(compact('entity','form')));
            }
            $form = $form->createView();
            return $this->success($page, $this->commonsResponseVars(compact('entity','form')));
            
        }catch(\Exception $e){
          return $this->failure($e);
        }
    }
150029
public function create(Request $request)
    {
        app('soda.interface')->setHeading('New Role');
        app('soda.interface')->breadcrumbs()->addLink(route('soda.roles.index'), 'Roles');

        try {
            $role = $this->roles->newInstance($request);
            $permissionIds = $this->roles->getPermissions();
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'role']));
        }

        return soda_cms_view('data.roles.view', compact('role', 'permissionIds'));
    }
106115
public function xhrFileUploadAction(Request $request)
    {
        if (!$request->files->has('file')) {
            return new JsonResponse(
                array(
                    'error' => 400,
                    'error_message' => 'File to upload have to be under "file" key.',
                ),
                400
            );
        }
        try {
            return new JsonResponse(
                array('file' => $this->container->get('synapse.media.domain')
                    ->upload($request->files->get('file'))
                    ->normalize(),
                ),
                201
            );
        } catch (UnsupportedFileException $e) {
            return new JsonResponse(
                array(
                    'error' => 400,
                    'error_message' => 'File isnt supported by Synapse.',
                    'error_full_message' => $e->getMessage(),
                ),
                400
            );
        }
    }
27152
private function createResponse(Request $request, string $schemaName = null, bool $batched)
    {
        if ('OPTIONS' === $request->getMethod()) {
            $response = new JsonResponse([], 200);
        } else {
            if (!\in_array($request->getMethod(), ['POST', 'GET'])) {
                return new Response('', 405);
            }
            $payload = $this->processQuery($request, $schemaName, $batched);
            $response = new JsonResponse($payload, 200);
        }
        $this->addCORSHeadersIfNeeded($response, $request);

        return $response;
    }
1054851
public function newAction(Request $request)
    {
        $windowMaker = new HubWindowMaker();
        $windowMaker->setHub($this->getCurrentProfile());
        $form = $this->createForm(new HubWindowMakerType($this->getCurrentProfile()), $windowMaker);

        if ($response = $this->processForm($request, $form, 'Hub_window_maker_show'))
        {
            return $response;
        }

        return $this->render('HarvestCloudCoreBundle:Hub/WindowMaker:new.html.twig', array(
            'form' => $form->createView(),
        ));
    }
308933
public function handleCreateFolder(SS_HTTPRequest $request)
    {

        if (!Injector::inst()->get('Folder')->canCreate()) {
            return $this->httpError(403);
        }

        $parentID = (int)$request->postVar('parentID');

        /** @var Folder $parentRecord */
        $parentRecord = Folder::get()->byID($parentID);

        $name = $request->postVar('title') ? $request->postVar('title') : _t('AssetAdmin.NEWFOLDER', "NewFolder");
        if ($parentRecord && $parentRecord->ID) {
            $filename = Controller::join_links($parentRecord->FullPath, $name);
        } else {
            $filename = Controller::join_links(ASSETS_PATH, $name);
        }

        /** @var Folder $record */
        $record = Folder::create(array(
            'ParentID' => $parentID,
            'Name' => basename($filename),
            'Title' => basename($filename),
            'Filename' => $filename
        ));

        // Ensure uniqueness
        $i = 2;
        if (substr($record->Filename, -1) == "/") {
            $baseFilename = substr($record->Filename, 0, -1);
        } else {
            $baseFilename = $record->Filename;
        }
        $baseFilename .= "-";
        while (file_exists($record->FullPath)) {
            $record->Filename = $baseFilename . $i . '/';
            $i++;
        }

        $record->Name = $record->Title = basename($record->Filename);

        mkdir($record->FullPath);
        @chmod($record->FullPath, (int)Config::inst()->get('Filesystem', 'file_create_mask'));

        $record->write();

        $response = new SS_HTTPResponse(
            Convert::array2json($this->createFolderJson($record)), 200
        );

        return $response->addHeader('Content-Type', 'application/json');
    }
256243
public function store(CreateCartItemRequest $request)
    {
        $errors = '';
        try {
            $this->cart->add(
                $request->shop_id,
                $request->product_id,
                $request->quantity,
                $request->get('option_values', []),
                $request->note
            );

            return response()->json([
                'errors' => false,
                'data' => $this->cart->items()
            ]);
        } catch (\Exception $e) {
            $errors = $e->getMessage();
        }

        return response()->json([
            'errors' => true,
            'message' => $errors,
            'data' => $this->cart->items()
        ]);
    }
349455
public function create(Request $request)
    {
        if ($request->wantsJson()) {
            return $this->validNotFoundJsonResponse();
        }

        $model = new $this->repository->model;

        $view = $this->getViewLocation(__FUNCTION__);
        $this->checkViewExists($view);

        return response()->view($view, compact('model'));
    }
1166132
public function update(HCUserRequest $request, string $id): JsonResponse
    {
        $this->connection->beginTransaction();

        try {
            $record = $this->service->updateUser(
                $id,
                $request->getUserInput(),
                $request->getRoles(),
                $request->getPersonalData()
            );

            if ($request->wantToActivate()) {
                $this->service->activateUser($record->id);
            }

            $this->connection->commit();

        } catch (\Throwable $exception) {
            $this->connection->rollBack();

            report($exception);

            return $this->response->error($exception->getMessage());
        }

        return $this->response->success(trans('HCCore::users.message.user_updated'), $record);
    }
1271448
public function deleteSoft(HCResourceGrabPropertyRequest $request): JsonResponse
{
    $this->connection->beginTransaction();

    try {
        $this->service->getRepository()->deleteSoft($request->getListIds());

        $this->connection->commit();
    } catch (\Throwable $exception) {
        $this->connection->rollBack();

        return $this->response->error($exception->getMessage());
    }

    return $this->response->success('Successfully deleted');
}
845166
public function newAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $template = new Template();
        $form = $this->container->get('form.factory')->create(TemplateType::class, $template);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $em->persist($template);
            $em->flush();

            return new JsonResponse([
                'success' => true,
                'url'     => $this->generateUrl('victoire_template_show', ['id' => $template->getId()]),
            ]);
        }

        return new JsonResponse(
            [
                'success' => true,
                'html'    => $this->container->get('templating')->render(
                    'VictoireTemplateBundle:Template:new.html.twig',
                    ['form' => $form->createView()]
                ),
            ]
        );
    }
721541
public function createAction(Request $request)
    {
        $form = $this->buildForm();

        if ($request->isMethod('POST') && $this->submitForm($form, $request)->isValid()) {
            try {
                $this->getDomainManager()->create($form->getData());
            } catch (DomainException $e) {
                $this->processException($e);
            }
        }

        return $this->processAction('create', $form, Response::HTTP_CREATED);
    }
336868
public function createRowAction(Request $request)
    {
        $container = $this->findContainer(intval($request->attributes->get('containerId')));

        $target = is_null($container->getCopy()) ? $container : $container->getCopy();

        try {
            $row = $this->getEditor()->createDefaultRow([], $target);
        } catch (EditorExceptionInterface $e) {
            return $this->handleException($e);
        }

        $this->validate($target);
        $this->persist($target);

        $viewBuilder = $this->getViewBuilder();

        $data = [
            'created'    => $viewBuilder->buildRow($row)->getAttributes()->getId(),
            'containers' => [$viewBuilder->buildContainer($container)],
        ];

        return $this->buildResponse($data, self::SERIALIZE_FULL);
    }
1006739
public function create(Request $request)
    {
        app('soda.interface')->setHeading('New User');
        app('soda.interface')->breadcrumbs()->addLink(route('soda.users.index'), 'Users');

        try {
            $user = $this->users->newInstance($request);
            $roleIds = $this->users->getRoles();
        } catch (Exception $e) {
            return $this->handleException($e, trans('soda::errors.create', ['object' => 'user']));
        }

        return soda_cms_view('data.users.view', compact('user', 'roleIds'));
    }
726318
public static function create_from_request($request) {
        if($type = $request->getVar('accept')) {
            try {
                if(array_key_exists($type, self::$lookup)) {
                    return self::create(self::$lookup[$type]);
                }
            } catch(\Exception $e) {}
        }
        $types = $request->getAcceptMimetypes();
        foreach($types as $type) {
            try {
                return self::create($type);
            } catch(RestUserException $e) {}
        }
        return self::create();
    }