The Domain Model

The N2 Domain Model

Okay, let's dive right in and look how a what a simple project would look like in Visual Studio. That's where most of the development effort is spent when developing an N2 CMS.

N2 allows you to define which types of content items are available in your CMS by creating .NET classes and decorating them with attributes. You can develop diverse functionality without creating any database tables or building any input forms. An important concept in N2 is the ContentItem class. This is the definition of a certain kind of page in our CMS. Instances of this class (objects) contain the content/data that we want to display using a template (an aspx page). 

Classes that inherit ContentItem have properties (e.g. the Text string) that expose the actual content. The properties are decorated with C# attributes that tell N2 how to handle the properties. For example, N2 can automatically generate editors to be used in the Edit interface (more on that in the next topic).

{TODO}

Figure 1. A bird's-eye view of the N2 content and view model.


Let's create a simple page type. We'll call this a TextPage, and as such we will create a corresponding class called TextPage. This is what TextPage looks like:

(source code)

By default, N2 inherits a few properties from ContentItem.

  • sss

Defining Additional Properties

Any properties that we want to expose through our Views, we need to define on our own. Let's define:

  • a title
  • some textual (body) content
  • an optional header image

Exposing Properties through Editors

Now that we've defined our properties, we will decorate them with C# attributes that tell N2 how to handle the properties. For example, N2 can automatically generate editors to be used in the Edit interface. (We'll discuss the Edit interface in more detail in the next topic)

ContentItem Editor Hierarchy

Figure 1. Editors are exposed via attributes on the properties defined in ContentItems.

 


 

  • Since TextPage inherits from N2.ContentItem (in this case a bit down the inheritance chain) it is treated by the N2 engine as a content type and made available for editing through the edit interface.
  • Take a quick look at that Text property before you move on. It has an interesting attribute that's used by the N2 engine to determine what kind of editor should be used to edit that property.

A property encapsulating our content

First, lets examine that attribute called EditableCheckbox. The attribute tells the N2 engine that this is a property that is editable in edit mode. Since it's the EditableCheckbox attribute a textarea is displayed when you edit this page. The parameters are just the name displayed in edit and the order of this property.

There are a number of built-in "editable" attributes. For more information, see the Editors chapter in the user guide.

Note the call to GetDetail in the getter. GetDetail gets values from a content detail collection and SetDetail updates the same value. Any serializable class is supported. The content detail collection contains all custom properties.