Share via


Register for a Course Use Case

The Register for a Course use case demonstrates how employees can register for a training course. The code that implements this use case demonstrates how an application can query SharePoint list items and add a new item to a list.

Using Custom Action

To begin the registration process, you can use either of two custom actions. One option is to navigate to the DisplayForm.aspx page for a specific training course and select the Register for Course action. The other option is to select the Register for Course action from the course's context menu that is located on the training dashboard page or the Training Course list page. You can also make a direct HTTP request for the CourseRegistration.aspx page (http://myserver/sites/training/CourseRegistration.aspx?ID=1). This request initiates the Page_Load handler that validates the request and calculates the fields that are used in the ASPX page. If the request passes this process, the employee sees the course registration form. The following illustration shows the form.

Training Management registration form

Ff650709.95098be8-05e2-426b-96f7-861985c3cefb(en-us,PandP.10).png

Clicking the Register for Course button adds a new item to the SharePoint registration list. This list contains items of the application-provided Registration content type.

To define a custom action, use the CustomAction element. The following XML (CourseRegistrationElement.xml) adds the Register for a Course action to the DisplayFormToolbar and to the EditControlBlock. It is located in Contoso.TrainingManagement\Forms\CourseRegistration.

  <CustomAction
       Id="695F3959-79C5-48b0-AACC-30DF5A731C81"
       Location="DisplayFormToolbar"
       Title="Register for Course"
       RegistrationType="ContentType"
       RegistrationId="0x01000CEE433CD7484DC5ADBEC636A5DD0C07">
    <UrlAction Url="~site/CourseRegistration.aspx?ID={ItemId}"/>
  </CustomAction>
  <CustomAction
        Id="0F446E21-839F-4938-9F1C-914237F15694"
        Location="EditControlBlock"
        Title="Register for Course"
        RegistrationType="ContentType"
        RegistrationId="0x01000CEE433CD7484DC5ADBEC636A5DD0C07">
    <UrlAction Url="~site/CourseRegistration.aspx?ID={ItemId}"/>
  </CustomAction>

The Id attribute is a programmer-generated GUID. The RegistrationType attribute associates the action with a content type and the RegistrationId attribute is the ID of the training course content type. The UrlAction attribute specifies the HTTP request that is generated when the user selects the action. The {ItemID} expression is replaced at run time with the ID of the selected list item.

Classes Used by the Course Registration Use Case

The following illustration shows the control flow for handling HTTP requests for the Course Registration use case.

Course registration control flow

Ff650709.fbb34341-afb2-4480-bca4-fbad6f94f294(en-us,PandP.10).png

The arrows in the preceding diagram represent the direction of the control flow. The following five classes are involved in the control flow:

  • CourseRegistration. This class is the ASPX page definition produced by the Visual Studio designer. Internet Information Services (IIS) invokes handler methods of the CourseRegistration class when it receives HTTP requests.
  • CourseRegistrationPresenter. This is the presenter for the CourseRegistration.aspx page. For more information about the presenter, see The Model-View-Presenter (MVP) Pattern and Unit Testing with Mock Objects in this guidance.
  • TrainingCourseRepository. This class provides Create/Update/Delete operations for the Training Courses SharePoint list.
  • RegistrationRepository. This class provides Create/Update/Delete operations for the SharePoint registration list.
  • ListItemRepository. This class encapsulates some of the details of interacting with SharePoint lists.

Registration Phases

The Registration use case occurs in two phases:

  • Page_Load phase
  • Submit_Click phase

These phases correspond to rendering the initial registration page in response to the HTTP request from an employee and to processing the button click when the employee confirms the request for a new registration.

The Registration use case includes the following topics:

Home page on MSDN | Community site