Issue#6 Course CRUD Functionality#23
Merged
JoeProgrammer88 merged 15 commits intomainfrom Mar 19, 2026
Merged
Conversation
Added a "Courses" navigation link in `_Layout.cshtml` visible only to authenticated users with the "Instructor" role. Implemented a `CoursesController` with full CRUD functionality, restricted to instructors via `[Authorize(Roles = "Instructor")]`. Created views (`Create.cshtml`, `Delete.cshtml`, `Details.cshtml`, `Edit.cshtml`, `Index.cshtml`) to manage courses, including forms for adding, editing, and deleting courses, as well as displaying course details and a list of all courses.
Replaced hardcoded role names with constants from a new `Roles` class to improve maintainability and consistency. Updated the `CoursesController` to use `Roles.Instructor` in the `[Authorize]` attribute. Modified `SeedData.cs` to use `Roles` constants for role creation and assignment. Updated `_Layout.cshtml` to use `Roles.Instructor` in role checks and added the necessary namespace import. Added a new `Roles.cs` file to define role constants for "Instructor" and "Student".
Updated `CoursesController` to inject `UserManager<ApplicationUser>` for retrieving the logged-in user's ID. Modified the `Create` action to associate courses with the currently logged-in instructor and adjusted `ModelState` validation accordingly. Updated `SeedData` to create a default user of type `Instructor`. Added a `Services` folder to the project structure in `SpeakingInBitsWeb.csproj`. Improved role-based authorization and user management by ensuring courses are linked to the correct instructor. Minor cleanup and updates to `using` statements and constructor dependencies.
Replaced the table-based layout for displaying courses with a modern, responsive card-based design using Bootstrap. Updated the page title and header to "Courses" for clarity. Added a "Create New Course" button for quick access to course creation. Introduced a conditional block to display an informational alert when no courses are available, encouraging users to create a new course. Improved overall styling and layout responsiveness for better user experience.
Removed [Bind] attribute to allow full Course object binding. Excluded CourseInstructor from ModelState validation to prevent unnecessary validation errors. Marked CourseInstructor navigation property as unchanged to avoid unintended updates during save.
The `Details` action method in `CoursesController` has been removed, along with the corresponding `Details.cshtml` view. This eliminates the ability to view detailed information about individual courses, including their `Title`, `CourseCode`, and `Description`. Links to edit a course or return to the course list from the details view have also been removed.
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces comprehensive course management functionality for instructors, including CRUD operations through a new controller and associated views. The implementation includes role-based access control and improves maintainability by introducing role constants.
- Added complete course CRUD functionality with instructor-only access control
- Introduced role constants to replace string literals throughout the codebase
- Updated navigation to conditionally show course management links for instructors
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| Controllers/CoursesController.cs | New controller implementing full CRUD operations for courses with instructor authorization |
| Models/Roles.cs | New constants class defining application role names for better maintainability |
| Models/SeedData.cs | Updated to use role constants instead of string literals |
| Views/Shared/_Layout.cshtml | Added conditional navigation link for courses visible only to instructors |
| Views/Courses/*.cshtml | Complete set of CRUD views for course management (Index, Create, Edit, Delete) |
| SpeakingInBitsWeb.csproj | Added placeholder Services folder to project structure |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ensure the Delete also verifies Course ownership Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Upgraded project dependencies to stable 10.0.x releases, removed EF Core Sqlite, and added Microsoft.Build packages. Updated EF Core Tools metadata for improved build configuration.
…s/SpeakingInBitsWeb into Issue#6-CourseCRUD
Edit and Delete actions now verify course ownership by checking the logged-in user against the course instructor. Only owners can modify or delete courses. Also, removed concurrency check from Edit POST for simplification.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+50
to
+66
| string? userId = _userManager.GetUserId(User); | ||
| Instructor? instructor = await _context.Users.OfType<Instructor>() | ||
| .FirstOrDefaultAsync(i => i.Id == userId); | ||
|
|
||
| if (instructor != null) | ||
| { | ||
| course.CourseInstructor = instructor; | ||
| } | ||
|
|
||
| // Remove CourseInstructor from ModelState since it's being set here programmatically | ||
| // It must be removed because it's happening after model binding and validation | ||
| ModelState.Remove(nameof(Course.CourseInstructor)); | ||
|
|
||
| if (ModelState.IsValid) | ||
| { | ||
| _context.Add(course); | ||
| await _context.SaveChangesAsync(); |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #6
This pull request introduces a new instructor-only course management feature to the application. It adds a
CoursesControllerfor CRUD operations, updates role management to use constants, and provides new views for listing, creating, editing, and deleting courses. The navigation bar is also updated to show the Courses link only to instructors.Course Management Feature:
CoursesControllerto handle course CRUD operations, restricted to users with the Instructor role. This includes logic to associate courses with the current instructor and ensures proper model validation and Entity Framework usage.Index,Create,Edit, andDelete, providing a user-friendly interface for instructors to manage courses. [1] [2] [3] [4]Role Management Improvements:
Rolesstatic class for role name constants, replacing string literals throughout the codebase for better maintainability.Rolesconstants and ensure the default instructor is created as anInstructorentity. [1] [2] [3]UI Enhancements:
_Layout.cshtmlto display the Courses link only for authenticated instructors, improving user experience and access control. [1] [2]Project Structure:
Servicesfolder in the project file, preparing for future service layer additions.