Skip to content

Instantly share code, notes, and snippets.

@copypastedeveloper
Last active December 22, 2018 22:37
Show Gist options
  • Select an option

  • Save copypastedeveloper/282f7d1a229f641ea991a89a3eddeac5 to your computer and use it in GitHub Desktop.

Select an option

Save copypastedeveloper/282f7d1a229f641ea991a89a3eddeac5 to your computer and use it in GitHub Desktop.
Classroom Excercise

Create an ERD and then a database representing these requirements:

Student

  1. First name
  2. Last name
  3. Slack handle
  4. The student's cohort
  5. The collection of exercises that the student is currently working on

Cohort

  1. The cohort's name (Evening Cohort 6, Day Cohort 25, etc.)
  2. The collection of students in the cohort.
  3. The collection of instructors in the cohort.

Instructor

  1. First name
  2. Last name
  3. Slack handle
  4. The instructor's cohort
  5. A method to assign an exercise to a student

Exercise

  1. An exercise can be assigned to many students.
  2. Name of exercise
  3. Language of exercise (JavaScript, Python, CSharp, etc.)

Building HTML Views with Razor

Read about Views in ASP.NET Core MVC to see how data is used in a Razor template.

Then, read the Tag Helpers in ASP.NET Core article to find out how to write custom elements to inject data into your DOM. Make sure you click on the Built-in Tag Helpers section to see a list of all of the ones available to you out of the box.

Initially, the Form Tag Helper, the Input Tag Helper, and the Label Tag Helper will be the ones you use the most.

Displaying a List of Cohorts

Your first task for this chapter is to start a new Visual Studio Web Application (MVC) project named StudentExercisesMVC. Once the project is created, you will need to install Dapper as a dependency. You can use the Package Manager console in Visual Studio, or you can do it from the command line with dotnet add package Dapper. If you do it from the command line, make sure you execute dotnet restore to enable it for your project.

Now you need to make a controller and a Razor template in order to manage the cohorts for your database.

Use scaffolding to...

  1. Create a CohortsController in your controllers directory.
  2. Create a Views > Cohorts directory and use the scaffolding to the create the Index, Details, Create, Edit, and Delete views.
  3. In your controller, use Dapper to execute SQL statements for all of those actions.

Displaying a List of Instructors

Use scaffolding to...

  1. Create a InstructorsController in your controllers directory.
  2. Create a Views > Instructors directory and use the scaffolding to the create the Index, Details, Create, Edit, and Delete views.
  3. In your controller, use Dapper to execute SQL statements for all of those actions.

When you create or edit an instructor, you should be able to assign the instructor to a cohort from a select element in the form.

Displaying a List of Students

Use scaffolding to...

  1. Create a StudentsController in your controllers directory.
  2. Create a Views > Students directory and use the scaffolding to the create the Index, Details, Create, Edit, and Delete views.
  3. In your controller, use Dapper to execute SQL statements for all of those actions.

When you create or edit a student, you should be able to assign the student to a cohort from a select element in the form.

Displaying a List of Exercises

Use scaffolding to...

  1. Create a ExercisesController in your controllers directory.
  2. Create a Views > Exercises directory and use the scaffolding to the create the Index, Details, Create, Edit, and Delete views.
  3. In your controller, use Dapper to execute SQL statements for all of those actions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment