Create a new record

@param Entity $entity

@return mixed

@throws Exception\ValidatorException
@throws Exception\RepositoryException
509091
public function create(Entity $entity)
    {
        if (!$entity->getValidator()->validate()) {
            throw new Exception\ValidatorException($entity->getValidator());
        }

        $values = $entity->getData();

        $reflection = $entity::getReflection();

        // Prevent to force empty primary property
        if ($reflection->hasPrimary()) {

            $primaryName = $reflection->getPrimaryProperty()->getName();

            if (empty($values[$primaryName])) {
                unset($values[$primaryName]);
            }
        }

        try {
            $primaryValue = $this->query()->insert($values)->run($this->connection);
        } catch (Exception\QueryException $e) {
            throw new Exception\RepositoryException($e->getMessage());
        }

        $this->_saveAssociated($primaryValue, $entity);

        return $primaryValue;
    }
976716
public function insert(Record $record, Entity $entity)
    {
        (new InsertRecord($record, $entity, $this))->execute();

        return $this;
    }
937877
public function insert(Entity $entity = null, Repository $repository = null)
    {
        $entity = $this->getEntityIfEmpty($entity);
        $repository = $entity->getRepositoryIfEmpty($repository);

        $this->trigger(['saving', 'inserting']);

        $insert = $repository->insert($this, $entity);

        $this->trigger(['inserted', 'saved']);

        $this->setOriginalFromData();

        return $insert;
    }
767426
public function insert($entity)
    {
        if (!$entity instanceof $this->entityClass) {
            throw new \InvalidArgumentException(
                "The entity to be inserted must be an instance of {$this->entityClass}."
            );
        }

        return $this->adapter->insert($this->entityTable, $entity->toArray());
    }
50934
public function createEntity($entity, TableNode $fields) {
    $this->models->get($entity)->store($fields->getRowsHash());
  }
529256
public function insert($instance, $entity = null)
    {
        list($instance, $entity) = $this->reassignEntity($instance, $entity);

        return new InsertQuery(
            $this->connection,
            $instance,
            $this->models->get($entity),
            $this->factory,
            $this->accessor,
            $this->dispatcher
        );
    }
967742
public function simpleInsert($entity){
        $simpleInsert = new SimpleInsert($entity,$this->getConfig());
        return $this->insert($simpleInsert);
    }
205737
private function createCreateForm(MessageType $entity)
    {
        $form = $this->createForm(MessageTypeType::class, $entity, array(
            'action' => $this->generateUrl('messagetype_create'),
            'method' => 'POST',
        ));
        $this->_addFunctionsToForm($form);

        $form->add('create_group', CheckboxType::class, array('label' => "This is a new group.", 'mapped' => false, 'required' => false));
        $form->add('submit', SubmitType::class, array('label' => 'Create'));

        return $form;
    }
721458
public function insert($entity)
    {
        $persistor = new DoctrinePersistor(
            $this->connection,
            $this->table,
            $this->entityRegistry->getEntityBuilder(),
            $this->entityRegistry
        );
        $persistor->insert($entity);
    }
664394
public static function generateDeleteRequest( Entity $entity ) {
        /* Generate the DeleteRequest message */
        $deleteRequestDOM = new DOMDocument();
        $deleteNode       = $deleteRequestDOM->appendChild( $deleteRequestDOM->createElementNS( 'http://schemas.microsoft.com/xrm/2011/Contracts/Services', 'Delete' ) );
        $deleteNode->appendChild( $deleteRequestDOM->createElement( 'entityName', $entity->logicalName ) );
        $deleteNode->appendChild( $deleteRequestDOM->createElement( 'id', $entity->ID ) );

        /* Return the DOMNode */

        return $deleteNode;
    }
497401
protected function createEditForm($entity)
    {
        $form = $this->createForm(
            $this->getEditFormType(), $entity, [
                'action' => $this->generateUrl($this->getRouteName() . "Edit", $this->getRouteParams(['id' => $entity->getId()])),
                'method' => 'POST',
            ]
        );

        return $form;
    }
1091028
protected function updateInDatabase(Entity $entity)
    {
        $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
        $values = $entity->getModifiedRowData();
        return $this->connection->query(
            'UPDATE %n SET %a WHERE %n = ?',
            $this->getTable(),
            $values,
            $primaryKey,
            $this->getIdValue($entity)
        );
    }
1077772
public function save(Entity $entity)
    {
        $requiredClass = Convention::nameToClass($this->getEntityName(), Convention::ENTITY_MASK);
        if (!$entity instanceof $requiredClass) {
            throw new Exception\RepositoryException(
                "Entity must be instance of ". $requiredClass . "!"
            );
        }

        $reflection = $entity::getReflection();
        if (!$reflection->hasPrimary()) {
            throw new Exception\RepositoryException(
                "Can not save entity without primary property!"
            );
        }

        $primaryName = $reflection->getPrimaryProperty()->getName();
        $primaryValue = $entity->{$primaryName};

        if ($primaryValue === null) {

            $primaryValue = $this->create($entity);
            if (Entity\Reflection\Property\Option\Primary::isEmpty($primaryValue)) {
                throw new RepositoryException(
                    "Entity was successfully created but returned primary is empty!"
                );
            }
            $entity->{$primaryName} = $primaryValue;
        } else {
            $this->update($entity, $primaryValue);
        }

        return $entity;
    }
985453
protected function insertIntoDatabase(Entity $entity)
    {
        $primaryKey = $this->mapper->getPrimaryKey($this->getTable());
        $values = $entity->getModifiedRowData();
        $this->connection->query(
            'INSERT INTO %n %v',
            $this->getTable(),
            $values
        );
        return isset($values[$primaryKey]) ? $values[$primaryKey] : $this->connection->getInsertId();
    }
1644
public function createForm($entity)
    {
        $formSpec = ArrayUtils::iteratorToArray($this->getFormSpecification($entity));
        if (!isset($formSpec['options']['merge_input_filter'])) {
            $formSpec['options']['merge_input_filter'] = true;
        }

        return $this->getFormFactory()->createForm($formSpec);
    }
1159160
public function create($entity, $isDeserialized = false)
    {
        if (!$entity) {
            throw new RestBadRequestException();
        }

        if (!$isDeserialized) {
            $entity = $this->denormalize($entity);
        }

        $errors = $this->filterAndValidate($entity);

        if ($errors) {
            throw new RestEntityValidationException($errors);
        }

        $this->manager->persist($entity);
        $this->manager->flush();

        return $entity;
    }
559469
public function post(Entity $entity)
    {
        if (!($entity instanceof Entity)) {
            throw new \InvalidArgumentException(
                sprintf(
                    'Invalid argument type passed to patch. Expecting Entity got %s',
                    gettype($entity)
                )
            );
        }

        $endPointUrl = $this->getEndPointUrl(get_class($entity));

        if (method_exists($entity, 'endPointUrlArg')) {
            $endPointUrl.= '/'.$entity->endPointUrlArg();
		}

		if (method_exists($entity, 'formatForPost')){
			$entity = $entity->formatForPost();
		}

        return $this->curlSend('POST', $entity, $endPointUrl);
    }