Sharing properties between content types, and action methods between controllers

It is a good idea to provide derived types from the Episerver content types PageData, BlockData and MediaData to share common properties among all the pages on the site. We should also consider to use that also on the controllers.

Considering the class diagram:

We can start to implement the Base[Classes] and Standard and Start page as:

using EPiServer.Core;
using EpiserverAdventures.Core.Constants;
using System.ComponentModel.DataAnnotations;

namespace EpiserverAdventures.Core.ContentTypes
{
    public abstract class BasePageData : PageData
    {
        [Display(Name = "Include in SEO Sitemap", Description = "Include on SEO sitemap.xml", GroupName = PageTabs.Navigation, Order = 1000)]
        public virtual bool IncludeInSitemap { get; set; }
    }
}
using EPiServer.Core;

namespace EpiserverAdventures.Core.ContentTypes
{
    public abstract class BaseBlockData : BlockData
    {

    }
}
using EPiServer.Core;

namespace EpiserverAdventures.Core.ContentTypes
{
    public abstract class BaseMediaData : MediaData
    {

    }
}

Therefore, we can start to create a standard page and define the start page for the site:

using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EpiserverAdventures.Core.Constants;
using System.ComponentModel.DataAnnotations;
using EpiserverAdventures.Core.ContentTypes;

namespace EpiserverAdventures.Core.Pages
{
    [ContentType(DisplayName = "Standard Page", GUID = "1D1A9C91-3F47-4ACE-90E2-06CBDFABC81A", Description = "Non specific page. Base page for content.", GroupName = PagesGroups.Content)]
    public class StandardPage : BasePageData
    {
        [CultureSpecific]
        [Display(Name = "Blocks", GroupName = SystemTabNames.Content, Order = 1000)]
        public virtual ContentArea Blocks { get; set; }
    }
}
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EpiserverAdventures.Core.Constants;

namespace EpiserverAdventures.Core.Pages.StartPage
{
    [ContentType(DisplayName = "Start Page", GUID = "BD710683-6F9D-4DA5-A2DC-5CFEF74723A8", Description = "Site start page", GroupName = PagesGroups.Content)]
    public class StartPage : StandardPage
    {
    }
}

I have decided to create a separated project from the episerver web project as:

Using the BasePageData model, every page will have the property “IncludeInSitemap” and active by default on page creation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: