Coaches are never permanently deleted immediately. Instead, they are marked as deleted but remain in the database.
When a coach is deleted, their students become "orphaned" and can be adopted by other coaches.
Soft-deleted records are automatically permanently deleted after 90 days to maintain database efficiency.
When a coach deletes their account, they are soft-deleted and their students become orphaned.
Students remain in the system with their data intact but without an assigned coach.
Other coaches can search for and adopt orphaned students using their email address.
Soft-deleted coaches remain in the database for 90 days, allowing for potential recovery.
After 90 days, soft-deleted coaches are permanently removed from the database.
As a coach, you can adopt orphaned students who previously worked with other coaches who have left the platform. Here's how:
Remember that adopting orphaned students counts toward your student limit based on your subscription tier:
Subscription Tier | Student Limit |
---|---|
Free | 5 students |
Basic | 20 students |
Professional | 50 students |
Unlimited | Unlimited students |
If you've reached your student limit, you'll need to upgrade your subscription before you can adopt more students.
The soft delete and orphaning system is configured with the following default settings:
The system logs all soft delete, orphaning, and adoption activities. You can monitor these activities in the application logs.
A test page is available at /test-soft-delete.html that allows you to:
The following fields were added to the Coach
model:
IsDeleted
(bool): Flag indicating if the coach has been soft-deletedDeletedAt
(DateTime?): Timestamp when the coach was soft-deletedDeletionReason
(string): Optional reason for deletionThe following changes were made to the Student
model:
CoachId
(int?): Made nullable to support orphaned studentsIsOrphaned
(bool): Flag indicating if the student is orphanedOrphanedAt
(DateTime?): Timestamp when the student was orphanedPreviousCoachId
(int?): ID of the student's previous coachThe DeleteService
implements the IDeleteService
interface and provides the following methods:
SoftDeleteCoachAsync
: Soft deletes a coach and orphans their studentsFindOrphanedStudentAsync
: Finds an orphaned student by emailAdoptOrphanedStudentAsync
: Adopts an orphaned studentPermanentlyDeleteOldRecordsAsync
: Permanently deletes old soft-deleted recordsThe CleanupService
is a background service that runs once per day to permanently delete old soft-deleted records.
It uses the DeleteService
to perform the actual deletion and logs the results.
The CoachesController
was updated to use the DeleteService
for soft deletes instead of hard deletes.
The Index
, Details
, and Edit
actions were updated to filter out soft-deleted coaches.
The StudentsController
was updated to add the following actions:
FindOrphaned
: Allows coaches to search for orphaned students by emailAdoptOrphaned
: Allows coaches to adopt orphaned students