Custom Admin Control in Orchard Using External Database

April 29, 2014

Blog | Technology | Custom Admin Control in Orchard Using External Database
Custom Admin Control in Orchard Using External Database

I recently had the task of delivering a custom admin interface within the Orchard dashboard that interacts with custom tables outside of the Orchard framework.  I wanted the experience to mirror what came out-of-the-box with Orchard.  The below steps will walk you through how to accomplish this feat.

This walkthrough was done using Orchard source version 1.7.2.

After performing preliminary website setup:

  • Run Orchard.exe from command prompt (inside Orchard.Web/bin)

  • Feature enable Orchard.CodeGeneration (you can also do this in the dashboard)

  • codegen module ModuleName /IncludeInSolution:true

  • codegen controller ModuleName AdminController (must be called AdminController)

    • Be sure to add an ActionResult to your controller “MyAction”

    • Create a view in the Views folder called “MyView”

    • Return this view from the ActionResult method you created

      • Public ActionResult MyAction(){ return View(“MyView”); }

  • Feature enable ModuleName (you can also do this in the dashboard)

  • At the project level, create a new class called AdminMenu.cs (ModuleName/AdminMenu.cs)

    • Implement INavigationProvider

    • Include a public property “T” of type Localizer

    • Include a public property “MenuName” of type string and return “admin” from the get routine: public string MenuName { get {return “admin”; } }

    • Include a public method “GetNavigation” that accepts a NavigationBuilder parameter called builder and returns void

      • Inside this method the menu item for the custom admin piece can be constructed

      • builder.Add(T(“Menu Title”), “3”, item => item.Action(“MyAction”, “Admin”, new { area = “ModuleName” }).Permission(StandardPermissions.AccessAdminPanel));

        • Where Menu Title is the title of the menu item

        • 3 is the position in the menu

        • MyAction is the ActionResult from the controller

        • Admin is the name of the controller

        • ModuleName is the name of the module

        • Permission ensures only admin’s can access

You should now see a new menu item called “Menu Title” at position 3 in the left rail.  Clicking on this menu item will load up your view “MyView.”  With this basic skeleton you can now construct customized admin pages using your own libraries and frameworks or utilizing some of the build in mechanisms in Orchard.  I chose to use Entity Framework and build my own editing and paging controls.  I also used the default Orchard classes for things like tables, buttons and spans to ensure this admin piece appeared to be part of the CMS.

John Rappel

Technical Lead
Tags
  • .NET
  • Content Management
  • Orchard

Recent Work

Check out what else we've been working on