Let us first see, what happens if you use the save() method directly on a product model like
* @var Magento\Catalog\Model\Product $product
The model class itself is
Within this class, search for the definition of the save() method.
None found right? Well, there's beforeSave() and afterSave(), ...
You will need to add sort order to search criteria
Add \Magento\Framework\Api\SortOrderBuilder $sortOrderBuilder as dependency in constructor.
public function getCollection()
$sortOrder = $this->sortOrderBuilder->setField('position')->setDirection('DESC')->create();
$searchCriteria = $this->searchCriteriaBuilder->...
Unfortunately, as of Magento 2.1-RC2 the Service Contracts method for store creation have not been implemented yet.
I'm afraid you'll have to stick with the method you used for now as Magento core files uses the same method, see Magento/Backend/Controller/Adminhtml/System/Store/Save.php :
$storeModel = $this->_objectManager->create('Magento\Store\...
You know all there is to know
save(), get(), getList(), delete(), deleteById()
Remember these are simply php classes and like any other can be customised to suit your needs
But generally if you start with those you know that your code is consistent.
I understood we have to use repositories instead of collections
AFAIK, when you use repositories you adhere to Magento 2 service contracts, which means that service interfaces and data interfaces are defined (but extensible by third-party modules).
Making it possible at run-time to change the result of the call to the getList() method of ...
It is encouraged to use data interfaces (e.g. \Magento\Catalog\Api\Data\ProductInterface) instead of the model directly and use the repositories to load and save models.
See Magento developer documentation
The repository classes should sit under Model IMHO.
But I reckon it's more important to setup service contract classes for those repositories than placing them in the right folder because if you setup proper service contracts for those classes, their location does not really matter as you will be using the service contracts classes instead ;)
Thanks to @raphael-at-digital-pianism. I have the following code to create stores ("store views" as wrote in "adminhtml"):
* Update/create store (frontname: "Store View").
* @param int $storeId ID to update existing store or 'null' to create new one
* @param string $name
* @param string $code
* @param int $websiteId
* @param int $groupId (...