protected function doPersist()
    {
        $environment   = $this->getEnvironment();
        $dataProvider  = $environment->getDataProvider($this->model->getProviderName());
        $inputProvider = $environment->getInputProvider();

        if (!$this->model->getMeta(ModelInterface::IS_CHANGED)) {
            return true;
        }

        $this->handlePrePersist();

        if ((null === $this->model->getId()) && $this->getManualSortingProperty()) {
            $models = $dataProvider->getEmptyCollection();
            $models->push($this->model);

            $controller = $environment->getController();

            if ($inputProvider->hasParameter('after')) {
                $after = ModelId::fromSerialized($inputProvider->getParameter('after'));

                $previousDataProvider = $environment->getDataProvider($after->getDataProviderName());
                $previousFetchConfig  = $previousDataProvider->getEmptyConfig();
                $previousFetchConfig->setId($after->getId());
                $previousModel = $previousDataProvider->fetch($previousFetchConfig);

                if ($previousModel) {
                    $controller->pasteAfter($previousModel, $models, $this->getManualSortingProperty());
                } else {
                    $controller->pasteTop($models, $this->getManualSortingProperty());
                }
            } elseif ($inputProvider->hasParameter('into')) {
                $into = ModelId::fromSerialized($inputProvider->getParameter('into'));

                $parentDataProvider = $environment->getDataProvider($into->getDataProviderName());
                $parentFetchConfig  = $parentDataProvider->getEmptyConfig();
                $parentFetchConfig->setId($into->getId());
                $parentModel = $parentDataProvider->fetch($parentFetchConfig);

                if ($parentModel) {
                    $controller->pasteInto($parentModel, $models, $this->getManualSortingProperty());
                } else {
                    $controller->pasteTop($models, $this->getManualSortingProperty());
                }
            } else {
                $controller->pasteTop($models, $this->getManualSortingProperty());
            }

            $environment->getClipboard()->clear()->saveTo($environment);
        } else {
            if (!$this->allValuesUnique()) {
                return false;
            }
            $editInformation = $GLOBALS['container']['dc-general.edit-information'];

            // Save the model.
            $dataProvider->save($this->model, $editInformation->uniformTime());
        }

        $this->handlePostPersist();

        $this->storeVersion($this->model);

        return true;
    }