Bug tracker: Create the SaveBug action

After you create the CreateBug action, you create the SaveBug action that creates an instance of the Bug content type and saves it in the database. You must add this action to the BugController class. To do this:

  1. Create a SaveBug method:
    1. In the BugController class, create a new method and name it SaveBug.
    2. As a return type specify ActionResult.
    3. Make the method accept an argument of type BugModel.
  2. Mark the method with the HttpPost attribute.
    You do this because you will be triggering this action in a POST request, you must mark the action with this attribute.
  3. Get the master ID of the parent project.
    The URL triggering this action will contain the ID of the live version of the specified project. To get the master ID, get an instance of the live version of the project. The ID of the master version is stored in the OriginalContentId property.
  4. Create a new Bug content item:
    1. Call the CreateDataItem method of the DynamicModuleManager instance.
    2. Pass the type of the Bug content item. You can find the exact type of the Bug content item in its auto-generated documentation. You can find the documentation on the module’s backend page in the module builder.
  5. Set the properties of the Bug instance.
    The BugModel argument will contain the values from the form.
    1. Set the properties of the Bug content item to the appropriate values of the BugModel instance.
    2. Set the UrlName and the ApprovalWorkflowState properties. The workflow state of the item must be Draft.
      After an admin publishes it, it will be visible in the frontend.
  6. Save the changes to the DynamicModuleManager instance.
  7. Redirect to the BugMaster view by using the RedirectToAction method of the Controller class.
  8. Redirect to the Index action of the BugController class.

GITHUB EXAMPLE: For more information about the SaveBug and SaveBugWorker methods, see the BugController.cs file of the downloaded sample project.

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?