Bug tracker: Create the BugController class
After you create the
ProjectController class, you create the BugController class. The bug controller contains the logic for the actions that you want to perform against the Bug content type. In this tutorial, the bugs are displayed and created in the frontend. The Index action returns a view populated with the available bugs for a specified project. The Create action creates a Bug item and stores it in the database. Note that in this step only the Index action is created.
To create a controller for the Bug content type:
- In Visual Studio, navigate to the Areas » BugTracker » Controllers folder, create a new class.
Name the class BugController.
- Make your class inherit the Controller class.
The Controller class is located in the System.Web.Mvc namespace.
- Create a method to query all available bugs from a specific project.
The method returns all available bugs form a specified project using an IQueryable. For more information how to query objects of your dynamic content type, you can refer to the generated documentation of your custom module. You can find it in the backend, on the page for configuring your custom module.
- Create an Index action:
- Create a method and name it Index.
- As a return type specify ActionResult.
The URL triggering this action will contain the ID of the live version of the specified project.
- Get the ID of the master version of the specified project by geting an instance of the live version of the project.
The ID of the master version is stored in the OriginalContentId property.
- Call the View method of the Controller class and pass the name of the desired view (in this case, BugMaster) and the query for the available bugs.
The query will be assigned to the Model property of the view.
- Return the result of the View method.
GITHUB EXAMPLE: For more information about the content of the file, see the BugController.cs file of the downloaded sample project.