Syllabus Schedule Project Labs Canvas Server Access CSS Tutorial Assignment 1 Assignment 2 Assignment 3 Assignment 4 Assignment 5 Assignment 6 Assignment 7 Assignment 8 Assignment 9

Assignment 03 - CRUD and Working with User Inputs

  1. People - This exercise extends the person model from A02 by creating a list of people and providing full CRUD functionality. It uses a generic List<> to hold the people and stores the List in a session object. In a later assignment we will update this exercise to use a database. Steps:
    1. Model: Copy this code for managing the List<> and session and add it to to your person model. It needs to be located inside the PersonModel class (immediately below the definition of the properties is a good location.) It provides five methods for CRUD that you will call from the controller.
    2. Controller: The controller will need a total of eight action methods to handle CRUD functionality:

      Action Method Purpose Input Parameters Returns (to view)
      index  List of all people none List of people
      Details List one person id person
      Create (HttpGet) Displays empty create form none nothing
      Create (HttpPost) Adds form data to List<> and redirects to index PersonModel person nothing (redirects to index)
      Update (HttpGet) Gets person based upon ID and populates update form id person
      Update (HttpGet) Updates person in List<> and redirects to index PersonModel person nothing (redirects to index)
      Delete (HttpGet) Displays the person to be deleted id person
      Delete (HttpPost) Deletes person in List<> and redirects to index PersonModel person nothing (redirects to index)

      Visual Studio will create a controller with stubs for eight ActionMethods. Right-click on on the controller folder and select "Add", "Controller", "Controller with Read/Write actions", name it PeopleController.

    3. The try catch blocks will suppress errors which makes debugging difficult.  Remove the three try/catch blocks, retaining the statements "return RedirectToAction("Index");" 
    4. The controller needs to access your PersonModel.  Add:

      using Mis324Assignments.Models;

    5. Three of the ActionMethods have the placeholder parameters "FormCollection collection."  Replace these with PersonModel person, which will hold the strongly-typed data from our form. ActionMethods
    6. The controller uses the methods in PersonModel to modify the list of people.  Each ActionMethod passes the appropriate data to the DataModel and the view as shown in the above table. For instance, the first two ActionMethods are shown in the image.
    7. Views: The views generated by VS are dependent upon the return statement in the ActionMethod so code the ActionMethods before creating the corresponding view.  Test each ActiionMethod before starting on the next one.
    8. Validation to your model with Data Annotations. Require both Fname and Lname and add a polite error message. You need to include the DataAnnotation namespace in your model.

      using System.ComponentModel.DataAnnotations;

    9. The redirects in the Create and Update controllers bypass the form validation. Fix this by checking data validity in the controller and returning to the form when the data is not valid. The test looks something line this: Is Valid


Submission instructions: Submit assignments via the Canvas course management system. Submit the full URL for each exercise in the assignment, listing the URLs in the same order that they are listed in the assignment. To minimize typos in URLs it is strongly recommended that you copy the URLs from the address bar of the browser rather than trying to type them. Incorrect URLs will not be graded and no credit will be given.

When pages are connected via navigation (as in your music store project) it is only necessary to submit the URL of the first page.