Creating the module

The module described in this section registers all necessary components to work with job applications and creates the backend pages that provide an overview of submitted job applications.

To implement the module, perform the following:

  1. From the context menu of the solution, click Add » New Item...

  2. In the left pane, select Visual C# » Code.

  3. Click Class and in the Name input field, enter JobsModule.

  4. Open the file JobsModule.cs and add the following namespaces:

    using System.Linq;
    using Jobs.Configuration;
    using Jobs.Localization;
    using Jobs.PublicControls;
    using Jobs.Resources;
    using Jobs.Services;
    using Telerik.Sitefinity.Abstractions;
    using Telerik.Sitefinity.Abstractions.VirtualPath.Configuration;
    using Telerik.Sitefinity.Configuration;
    using Telerik.Sitefinity.Localization;
    using Telerik.Sitefinity.Modules.GenericContent;
    using Telerik.Sitefinity.Modules.Pages.Configuration;
    using Telerik.Sitefinity.Pages.Model;
    using Telerik.Sitefinity.Services;
    using Telerik.Sitefinity.Utilities.TypeConverters;
    using Telerik.Sitefinity.Web.UI.ContentUI;
  5. Change the class definition to:

    public class JobsModule : ContentModuleBase
    {
     
    }
  6. Define the module name by pasting the following code:

    public const string ModuleName = "Jobs";
  7. Add the following properties:

    public static readonly Guid JobsPageGroupID = new Guid("13FA3CB0-6F00-4DFB-A534-28EA60252A16");
    public static readonly Guid JobsModuleLandingPage = new Guid("A52C36E1-3D29-4F39-BB8D-BB1F064E556A");
    public static string JobsVirtualPath = "~/SFJobs/";
     
    public override Type[] Managers
    {
        get
        {
            return new[] { typeof(JobsManager) };
        }
    }
     
    public override Guid LandingPageId
    {
        get
        {
            return JobsModule.JobsModuleLandingPage;
        }
    }
     
    public Guid SubPageId
    {
        get
        {
            return JobsModule.JobsPageGroupID;
        }
    }
  8. Override the Initialize method of the ContentModuleBase class.

    In it you must register the configuration class for the module and the backend service. Following is the code for the method.

    public override void Initialize(ModuleSettings settings)
    {
        base.Initialize(settings);
        Config.RegisterSection<JobsConfig>();
        Res.RegisterResource<JobsResources>();
     
        ObjectFactory.RegisterWebService(typeof(JobsBackendService), "Sitefinity/Services/Content/Jobs.svc");
        TypeResolutionService.RegisterAssembly(typeof(JobsModule).Assembly.GetName());
    }
  9. Override the Install method of the ContentModuleBase class.

    The method installs the module in Sitefinity system.

    public override void Install(SiteInitializer initializer)
    {
        base.Install(initializer);
        this.InstallCustomVirtualPaths(initializer);
    }
     
    private void InstallCustomVirtualPaths(SiteInitializer initialzer)
    {
        var virtualPathConfig = initialzer.Context.GetConfig<VirtualPathSettingsConfig>();
        var jobsModuleVirtualPathConfig = new VirtualPathElement(virtualPathConfig.VirtualPaths)
        {
            VirtualPath = JobsModule.JobsVirtualPath + "*",
            ResolverName = "EmbeddedResourceResolver",
            ResourceLocation = "Jobs"
        };
        if (!virtualPathConfig.VirtualPaths.ContainsKey(JobsModule.JobsVirtualPath + "*"))
            virtualPathConfig.VirtualPaths.Add(jobsModuleVirtualPathConfig);
    }

    In the InstallCustomVirtualPaths method you must register the prefixes used by the LayoutTemplatePath properties of your frontend controls.

  10. Implement the ContentModuleBase by pasting the following code:

    public override void Upgrade(SiteInitializer initializer, Version upgradeFrom)
    { }
     
    protected override ConfigSection GetModuleConfig()
    {
        return Config.Get<JobsConfig>();
    }
     
    protected override void InstallTaxonomies(SiteInitializer initializer)
    { }
  11. To install the backend pages, add the following method:

    protected override void InstallPages(SiteInitializer initializer)
    {
        var pageManager = initializer.PageManager;
        var moduleNode = pageManager.GetPageNode(SiteInitializer.ModulesNodeId);
     
        var jobsNode = pageManager.GetPageNodes().Where(p => p.Id == JobsModule.JobsPageGroupID).SingleOrDefault();
        if (jobsNode == null)
        {
            jobsNode = initializer.CreatePageNode(JobsModule.JobsPageGroupID, moduleNode, NodeType.Group);
     
            jobsNode.Name = JobsModule.ModuleName;
            jobsNode.ShowInNavigation = true;
            jobsNode.Attributes["ModuleName"] = JobsModule.ModuleName;
            jobsNode.Title = JobsModule.ModuleName;
            jobsNode.UrlName = JobsModule.ModuleName;
            jobsNode.Description = "Module for managing job applications";
        }
     
        var landingPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id == this.LandingPageId);
     
        if (landingPage == null)
        {
            var pageInfo = new PageDataElement()
            {
                PageId = this.LandingPageId,
                Name = "Jobs",
                MenuName = "Jobs Module",
                UrlName = "Jobs",
                Description = "JobsLandingPageDescription",
                HtmlTitle = "Jobs Module",
                ResourceClassId = typeof(JobsResources).Name,
                IncludeScriptManager = true,
                ShowInNavigation = false,
                EnableViewState = false,
                TemplateName = SiteInitializer.BackendTemplateName,
            };
     
            pageInfo.Parameters["ModuleName"] = JobsModule.ModuleName;
            var backendView = new BackendContentView()
            {
                ModuleName = JobsModule.ModuleName,
                ControlDefinitionName = JobsDefinitions.BackendDefinitionName,
            };
     
            initializer.CreatePageFromConfiguration(pageInfo, jobsNode, backendView);
        }
    }
  12. To install the controls in the Sitefinity toolbox, add the following method:

    protected override void InstallConfiguration(SiteInitializer initializer)
    {
        var config = initializer.Context.GetConfig<ToolboxesConfig>();
        var pageControls = config.Toolboxes["PageControls"];
        var section = pageControls
            .Sections
            .Where<ToolboxSection>(e => e.Name == ToolboxesConfig.ContentToolboxSectionName)
            .FirstOrDefault();
     
        section.Tools.Add(new ToolboxItem(section.Tools)
        {
            Name = "JobApplicationUpload",
            Title = "JobApplicationsUploadTitle",
            Description = "JobApplicationsUploadDescription",
            ResourceClassId = typeof(JobsResources).Name,
            ControlType = typeof(JobApplicationUpload).AssemblyQualifiedName
        });
    }

JobsModule inherits from ContentModuleBase - the default base class for content-based modules. The property public override Type[] Managers returns the manager, which this module uses. Initialize is executed every time Sitefinity starts. The method registers the configuration class - JobsConfig, the resource class, which contains localized strings – JobsResources and the backend service.InstallConfiguration registers the upload control in the Sitefinity toolbox. The JobsResources class is defined in Localization.

InstallPages creates the necessary backend pages using definitions. Definitions are the properties that a control needs to be displayed in the user interface. First, you get the modules node. Then, you create a manager to get the jobs node. If the jobs node is not yet created, you create it. After the jobs node is created, you define the backend view.

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK