Access Orchard functionality from a controller

Topics: Writing modules
Oct 3, 2012 at 4:51 PM

I need to do two things from [Themed] controllers:


1. Save to DB and restore from DB a very simple domain model containing 3 classes and 2 enums.


2. I have a 1.5 multilevel menu, I want to highlight an option in the top menu and display the second level, without highlighting.


I'd greatly appreciate your advice :-)

Oct 6, 2012 at 2:52 AM
Edited Oct 6, 2012 at 2:53 AM
  1. Use IRepository<T> to read from and write to DB. One way is to inject 3 IRepositories into your controller. However I would consider creating an application service class that in turn gets the 3 repositories. That way, your controller only uses that service class.
  2. Use CSS to style your menu items.
Oct 8, 2012 at 10:07 AM

Thanks sfmskywalker.


On 2. - the thing is the second level menu is not shown at all on the URLs returned by my controller. I don't want the controller pages to have a menu entry, but I want to show the second level for a specific first level entry.

Oct 19, 2012 at 4:25 AM
Edited Oct 19, 2012 at 4:26 AM

Ok, so what you could try is create a ShapeTableProvider class that will generate alternates for the MenuItem shape based on anything that makes sense in your case. For example, you could add a field to your menu item content type that acts as an "ID" or "Name" of the menu item. From your shape table provider, describe the MenuItem shape and accesss its Content property that will hold a reference to your menu item content item that will have the text field attached. Now that you have alternates based on a menu item "ID" or "name" (or anything else that makes sense for your case), you can create a template for the menu item in question.