Skip to content

Issue#6 Course CRUD Functionality#23

Merged
JoeProgrammer88 merged 15 commits intomainfrom
Issue#6-CourseCRUD
Mar 19, 2026
Merged

Issue#6 Course CRUD Functionality#23
JoeProgrammer88 merged 15 commits intomainfrom
Issue#6-CourseCRUD

Conversation

@JoeProgrammer88
Copy link
Copy Markdown
Member

Closes #6

This pull request introduces a new instructor-only course management feature to the application. It adds a CoursesController for 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:

  • Added CoursesController to 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.
  • Created Razor views for courses: Index, Create, Edit, and Delete, providing a user-friendly interface for instructors to manage courses. [1] [2] [3] [4]

Role Management Improvements:

  • Introduced the Roles static class for role name constants, replacing string literals throughout the codebase for better maintainability.
  • Updated role seeding and default user creation logic to use the new Roles constants and ensure the default instructor is created as an Instructor entity. [1] [2] [3]

UI Enhancements:

  • Modified the navigation bar in _Layout.cshtml to display the Courses link only for authenticated instructors, improving user experience and access control. [1] [2]

Project Structure:

  • Added a placeholder for a Services folder in the project file, preparing for future service layer additions.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread SpeakingInBitsWeb/Controllers/CoursesController.cs Outdated
Comment thread SpeakingInBitsWeb/Controllers/CoursesController.cs Outdated
Comment thread SpeakingInBitsWeb/Controllers/CoursesController.cs Outdated
Comment thread SpeakingInBitsWeb/Controllers/CoursesController.cs Outdated
Comment thread SpeakingInBitsWeb/Controllers/CoursesController.cs Outdated
JoeProgrammer88 and others added 5 commits October 10, 2025 12:10
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.
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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread SpeakingInBitsWeb/Controllers/CoursesController.cs
Comment thread SpeakingInBitsWeb/Controllers/CoursesController.cs Outdated
Comment thread SpeakingInBitsWeb/SpeakingInBitsWeb.csproj Outdated
Comment thread SpeakingInBitsWeb/Views/Shared/_Layout.cshtml Outdated
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();
JoeProgrammer88 and others added 4 commits March 19, 2026 10:36
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>
@JoeProgrammer88 JoeProgrammer88 merged commit 8b21947 into main Mar 19, 2026
1 check passed
@JoeProgrammer88 JoeProgrammer88 deleted the Issue#6-CourseCRUD branch March 19, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Give instructors CRUD functionality for their own courses

2 participants