Content service

The ContentService class is the most central API class. The class takes care of all content related functionality such as searching, inserting content and fetching content. The following table displays the most used and important functions. The complete API is exposed through Visual Studio IntelliSense.

Function name Description
Get Gets a content based on the content id or path
Get<T> Gets a content of content type <T> based on the content id path
GetByPermalink Gets a content based on its permalink
GetAncestors Gets the ancestors of a Content item, starting with the root item and ending with the parent of the Content item
GetChildren Gets the children of a content item
GetChildren<T> Gets the children of type <T> for a content item
GetDecendants Returns the descendants of a Content item. The descendants are sorted like a tree
GetDecendants<T> Returns the descendants of a specified content type <T> of a Content item. The descendants are sorted like a tree
GetAll<T> Gets all content items that are in the inheritance hierarchy of type <T>
GetPath Gets the path of a Content item. The path is the combined slug of the Content and all it's ancestors.
Search Performs a search according to the specified ContentQuery object
Insert Inserts a new content item in the repository
Update Updates a content item
Copy Creates a copy of the specified translation of a content item
Move Moves a Content item and its' descendants to a new place in the content hierarchy
Delete Deletes all translations of a Content object and it's descendants

Examples

The following examples are extracts from code.

Example 1. Get the content with id 25.

var content = ContentService.Get(25);

 

Example 2. Get the content with id 25 and cast it to Mindroute.Lemoon.Modules.BlogModule.Blog. If the content type with id 25 is not of type Blog or derived from that type null will be returned.

var blog = ContentService.Get<Blog>(25);

 

Example 3. Get the content with the slug "products".

var content = ContentService.GetBySlug("products");

 

Example 4. Get a list of children for the content with id 25.

var children = ContentService.GetChildren(25);

 

Example 5. Insert a new content as a child to the content with id 25.

var page = new Page();
            
page.Title = "A page";
page.Body = "Text...";
page.ParentID = 25;

ContentService.Insert(page);