This video is available to students only

Creating Instructor Page

In this lesson, we're going to create the instructor page

Creating instructor page#

Now that we have given an option to our users to become an instructor, let's start working on the instructor page. Inside pages, we can create the instructor page. We can display the unpublished courses on the left and on the right, and we can give a button which will give an option to create a new course. Let's register this page inside App.tsx file with route/instructor.

Coming back to the Instructor page, let's create a div with class instructor. Now we can keep the courses on left and the button on right. Let's create two divs; instructor left and instructor right. Now we need to show the courses made by the user, so we can create a new endpoint inside UsersController.

This will be an authorized request. This will be a get request with name unpublishedCourses. We will return list of course from this method. Inside, we can create a new variable called courses which will be equal to context dot courses dot where x dot instructor is equal to user dot identity dot name. Since our username is unique, we can be assured that returned courses will only be made by this user. I'm trying to show only the unpublished courses. But right now, we don't have published property. Let's add the published property inside course model with default property being false. Since we are here, we can add a default image link because I'm not adding image uploading service inside this course. So our course creation field won't have an option to add an image. Please copy the image link and make it the default.

Default image link

Entity/Course.cs

Let's go back to Users controller and add one more Where condition here. Now we only want to return the unpublished courses here so let's check where the published property is false. Finally, make it a list and return it. Also, we want to return only the published courses, so inside CoursesWithCategoriesSpecification, we can add published condition. Now that we have added new property inside Course model, we need to create a new migration. And now, we are only returning the courses which are published and we don't have published property inside courses, so let's add it and make it true. We can now drop the database and create a new migration.

Infrastructure/SeedData/courses.json

API/Controllers/UsersController.cs

Start a new discussion. All notification go to the author.