Using .netTiers with mojoPortal

Over many years of programming, I have used various methods to streamline creating web applications. The efforts were geared towards one goal: produce applications in a repeatable and efficient manner. Often, clients wanted to integrate a public facing website with internal web applications. The main purpose was to allow clients to be self-sufficient in maintaining the content of the website but not interfere with the applications.

Those thoughts led to researching various open source content management systems and code generation tools. I had written a couple of code generation tools over the years using different architectures and techniques. The obvious benefit was that the code on one project was architected and had been tested on other projects. However, I wanted a solution that would provide more CMS features and integrate robust application architecture.

We came across mojoPortal and CodeSmith with the netTiers framework. They are front-runners for addressing these concepts. The only problem is that they do not integrate out-of-the-box. After a few brainstorming sessions, it seemed not only possible but absolutely essential that we find a solution to integrate these two awesome products.

Over the next few days, I will post the results of our integration efforts. This will be aimed at describing the overall process and not meant as a de-facto standard. There will be various implementation strategies that we choose for the sake of “making it work." If you discover better ways to make it work, please share in a constructive manner.

With that being said, let’s begin our journey…

Prepare for Integration (Part 1)

We will start with a simple example that uses one table in a SQL Database. ACMETools is the name of the database. Acme.Tools is the namespace used when the netTiers code was generated using CodeSmith. I will use the Organization table from the database in the example.

NOTE: If you want to debug along with the mojoPortal code, include the netTiers projects associated with the DLLs in the mojoPortal solution file.

Create a database called ACMETools.

Create a user named ACMEToolsUser with the password ACMETools.

Provide the ACMEToolsUser with DBO permissions to the ACMETools database.

Open the netTiers generated Visual Studio solution file to modify the code.

Create a folder named mojoPortal under the Admin folder.

Create two folders under the mojoPortal folder named PageControls and UserControls.

Copy the contents of the netTiers generated UserControls folder to the mojoPortal\UserControls folder. This will make it easier to copy the files to the mojoPortal later.

CodeSmith / netTiers genrates two pages for each table selected in your code generation. In this example, it created Organization.aspx and OrganizationEdit.aspx for the Organization table.

Copy the netTiers generated Organization.aspx and the OrganizationEdit.aspx files to the mojoPortal\PageControls folder. Do not copy the associated code-behind (*.cs) files.

Rename the mojoPortal\PageControls\Organization.aspx file to OrganizationListPage.ascx.

Rename the mojoPortal\PageControls\OrganizationEdit.aspx file to OrganizationEditPage.ascx.

Modify the netTiers Code for the mojoPortal Site (Part 2)

So far, we have shown how to lay a foundation for integrating mojoPortal and netTiers generated code. Now, we will continue the integration by showing the changes we need to make to the generated code.

Modify the OrganizationListPage.ascx file

Change the Page declaration to a Control declaration. Notice in the Control declaration that we inherit from the mojoPortal.Web.SiteModuleControl.

Copy the code from the netTiers Organization.aspx.cs file to the OrganizationListPage.ascx. In the ascx file, add the <script runat="server"> tag. This should be placed after the Control declaration at the top of the file. If the Organization table is related to another table, the code will have a SelectedIndexChanged event for each related table.

NOTE: If your tables had Foreign Keys to other tables, netTiers automatically creates drop down lists for you. Watch for these in the code so you can correct the page names if need be.

Create the mojoPortal Pages (Part 3)

So far, we have shown how to lay a foundation for integrating mojoPortal and netTiers generated code and the changes needed to the generated code.

Finally, we will show the steps for creating the pages and using the controls from the netTiers generated code.

Copy the folder and files from the netTiers Admin\mojoPortal folder to the mojoPortal Modules folder. This will contain the PageControls and the UserControls folders. You will have to FTP the files if you are not running the mojoPortal site locally or on a network machine.

Sign in to the mojoPortal sign using an Administrator level account.

Click Administration.

Click Advanced Tools.

Click Feature Installation/Configuration.

Click Add New Feature.

Enter the necessary information to add a feature

Feature Name Resource Key – OrganizationListPage

Resource File – leave blank

Control Source – Modules/PageControls/OrganizationListPage.ascx

Feature Guid – leave the generated Guid in place. It is a good idea to copy the Guid and paste as a comment in the code for your control.

You can leave everything else as is.

Click the Update button.

The control will now appear in the list of features.

Click New Page

Parent Page – select Home.

Page Name – Organization.aspx.

Page Title Override – Organization Search.

Url - ~/Ogranization.aspx.

Select the other options as desired. Just leave the defaults.

Click Create New Page.

Click Add/Remove Features On This Page

Feature – Select OrganizationListPage

Title – Search Organization

Location – Center

Click Create New Content

That creates the Search\List page for the Organization. Next, we will follow the same process for creating the OrganizationEdit page.

Click Administration.

Click Advanced Tools.

Click Feature Installation/Configuration.

Click Add New Feature.

Enter the necessary information to add a feature

Feature Name Resource Key – OrganizationEditPage

Resource File – leave blank

Control Source – Modules/PageControls/OrganizationEditPage.ascx

Feature Guid – leave the generated Guid in place. It is a good idea to copy the Guid and paste as a comment in the code for your control.

You can leave everything else as is.

Click the Update button.

The control will now appear in the list of features.

Click New Page

Parent Page – select Home.

Page Name – OrganizationEdit.aspx.

Page Title Override – Organization Edit.

Url - ~/OgranizationEdit.aspx.

Leave the defaults for the other options.

Click Create New Page.

Click Add/Remove Features On This Page

Feature – Select OrganizationEditPage

Title – Organization

Location – Center

Click Create New Content

Summary

We hope this helps generate ideas for you to integrate mojoPortal and netTiers. We would love to hear and share ideas with others out there that are trying to accomplish the same goal.