Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,31 +91,31 @@ public async Task<IEnumerable<CertificateDto>> GetCertificatesByStudentIdAsync(G
{
await Task.CompletedTask; // Simulate async operation

var certificates = _certificates.Where(c => c.StudentId == studentId);
var certificates = _certificates.Where(certificate => certificate.StudentId == studentId);
return certificates.Select(MapToDto);
}

public async Task<CertificateDto?> GetCertificateByIdAsync(Guid certificateId)
{
await Task.CompletedTask; // Simulate async operation

var certificate = _certificates.FirstOrDefault(c => c.CertificateId == certificateId);
var certificate = _certificates.FirstOrDefault(cert => cert.CertificateId == certificateId);
return certificate != null ? MapToDto(certificate) : null;
}

public async Task<IEnumerable<CertificateDto>> GetCertificatesByStudentNameAsync(string studentName)
{
await Task.CompletedTask; // Simulate async operation

var matchingStudents = _students.Where(s =>
$"{s.FirstName} {s.LastName}".Contains(studentName, StringComparison.OrdinalIgnoreCase) ||
s.FirstName.Contains(studentName, StringComparison.OrdinalIgnoreCase) ||
s.LastName.Contains(studentName, StringComparison.OrdinalIgnoreCase));
var matchingStudents = _students.Where(student =>
$"{student.FirstName} {student.LastName}".Contains(studentName, StringComparison.OrdinalIgnoreCase) ||
student.FirstName.Contains(studentName, StringComparison.OrdinalIgnoreCase) ||
student.LastName.Contains(studentName, StringComparison.OrdinalIgnoreCase));

var certificates = new List<Certificate>();
foreach (var student in matchingStudents)
{
certificates.AddRange(_certificates.Where(c => c.StudentId == student.StudentId));
certificates.AddRange(_certificates.Where(certificate => certificate.StudentId == student.StudentId));
}

return certificates.Select(MapToDto);
Expand Down Expand Up @@ -150,8 +150,8 @@ public string GenerateCertificateNumber()

private CertificateDto MapToDto(Certificate certificate)
{
var student = _students.FirstOrDefault(s => s.StudentId == certificate.StudentId);
var course = _courses.FirstOrDefault(c => c.CourseId == certificate.CourseId);
var student = _students.FirstOrDefault(stud => stud.StudentId == certificate.StudentId);
var course = _courses.FirstOrDefault(crs => crs.CourseId == certificate.CourseId);

return new CertificateDto
{
Expand Down
4 changes: 2 additions & 2 deletions api/CourseRegistration.Application/Services/CourseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<PagedResponseDto<CourseDto>> GetCoursesAsync(int page = 1, int
else
{
courses = await _unitOfWork.Courses.GetPagedAsync(page, pageSize);
totalCourses = await _unitOfWork.Courses.CountAsync(c => ((Course)c).IsActive);
totalCourses = await _unitOfWork.Courses.CountAsync(course => ((Course)course).IsActive);
}

var courseDtos = _mapper.Map<IEnumerable<CourseDto>>(courses);
Expand Down Expand Up @@ -129,7 +129,7 @@ public async Task<bool> DeleteCourseAsync(Guid id)

// Check if course has active registrations
var activeRegistrations = await _unitOfWork.Registrations.GetByCourseIdAsync(id);
if (activeRegistrations.Any(r => r.Status == Domain.Enums.RegistrationStatus.Confirmed))
if (activeRegistrations.Any(registration => registration.Status == Domain.Enums.RegistrationStatus.Confirmed))
{
throw new InvalidOperationException("Cannot delete a course with active registrations.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<PagedResponseDto<StudentDto>> GetStudentsAsync(int page = 1, i
if (pageSize > 100) pageSize = 100;

var students = await _unitOfWork.Students.GetPagedAsync(page, pageSize);
var totalStudents = await _unitOfWork.Students.CountAsync(s => ((Student)s).IsActive);
var totalStudents = await _unitOfWork.Students.CountAsync(student => ((Student)student).IsActive);

var studentDtos = _mapper.Map<IEnumerable<StudentDto>>(students);

Expand Down
2 changes: 1 addition & 1 deletion api/CourseRegistration.Domain/Entities/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ public class Course
/// Computed property for current enrollment count
/// </summary>
[NotMapped]
public int CurrentEnrollment => Registrations?.Count(r => r.Status == Enums.RegistrationStatus.Confirmed) ?? 0;
public int CurrentEnrollment => Registrations?.Count(registration => registration.Status == Enums.RegistrationStatus.Confirmed) ?? 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,70 +42,70 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
// Configure Student entity
modelBuilder.Entity<Student>(entity =>
{
entity.HasKey(s => s.StudentId);
entity.HasIndex(s => s.Email).IsUnique();
entity.Property(s => s.FirstName).IsRequired().HasMaxLength(50);
entity.Property(s => s.LastName).IsRequired().HasMaxLength(50);
entity.Property(s => s.Email).IsRequired().HasMaxLength(256);
entity.Property(s => s.PhoneNumber).HasMaxLength(20);
entity.Property(s => s.DateOfBirth).IsRequired();
entity.Property(s => s.CreatedAt).IsRequired();
entity.Property(s => s.UpdatedAt).IsRequired();
entity.Property(s => s.IsActive).IsRequired();
entity.HasKey(student => student.StudentId);
entity.HasIndex(student => student.Email).IsUnique();
entity.Property(student => student.FirstName).IsRequired().HasMaxLength(50);
entity.Property(student => student.LastName).IsRequired().HasMaxLength(50);
entity.Property(student => student.Email).IsRequired().HasMaxLength(256);
entity.Property(student => student.PhoneNumber).HasMaxLength(20);
entity.Property(student => student.DateOfBirth).IsRequired();
entity.Property(student => student.CreatedAt).IsRequired();
entity.Property(student => student.UpdatedAt).IsRequired();
entity.Property(student => student.IsActive).IsRequired();

// Configure relationships
entity.HasMany(s => s.Registrations)
.WithOne(r => r.Student)
.HasForeignKey(r => r.StudentId)
entity.HasMany(student => student.Registrations)
.WithOne(registration => registration.Student)
.HasForeignKey(registration => registration.StudentId)
.OnDelete(DeleteBehavior.Cascade);
});

// Configure Course entity
modelBuilder.Entity<Course>(entity =>
{
entity.HasKey(c => c.CourseId);
entity.Property(c => c.CourseName).IsRequired().HasMaxLength(100);
entity.Property(c => c.Description).HasMaxLength(500);
entity.Property(c => c.InstructorName).IsRequired().HasMaxLength(100);
entity.Property(c => c.StartDate).IsRequired();
entity.Property(c => c.EndDate).IsRequired();
entity.Property(c => c.Schedule).IsRequired().HasMaxLength(100);
entity.Property(c => c.IsActive).IsRequired();
entity.Property(c => c.CreatedAt).IsRequired();
entity.Property(c => c.UpdatedAt).IsRequired();
entity.HasKey(course => course.CourseId);
entity.Property(course => course.CourseName).IsRequired().HasMaxLength(100);
entity.Property(course => course.Description).HasMaxLength(500);
entity.Property(course => course.InstructorName).IsRequired().HasMaxLength(100);
entity.Property(course => course.StartDate).IsRequired();
entity.Property(course => course.EndDate).IsRequired();
entity.Property(course => course.Schedule).IsRequired().HasMaxLength(100);
entity.Property(course => course.IsActive).IsRequired();
entity.Property(course => course.CreatedAt).IsRequired();
entity.Property(course => course.UpdatedAt).IsRequired();

// Configure relationships
entity.HasMany(c => c.Registrations)
.WithOne(r => r.Course)
.HasForeignKey(r => r.CourseId)
entity.HasMany(course => course.Registrations)
.WithOne(registration => registration.Course)
.HasForeignKey(registration => registration.CourseId)
.OnDelete(DeleteBehavior.Cascade);
});

// Configure Registration entity
modelBuilder.Entity<Registration>(entity =>
{
entity.HasKey(r => r.RegistrationId);
entity.Property(r => r.StudentId).IsRequired();
entity.Property(r => r.CourseId).IsRequired();
entity.Property(r => r.RegistrationDate).IsRequired();
entity.Property(r => r.Status).IsRequired()
entity.HasKey(registration => registration.RegistrationId);
entity.Property(registration => registration.StudentId).IsRequired();
entity.Property(registration => registration.CourseId).IsRequired();
entity.Property(registration => registration.RegistrationDate).IsRequired();
entity.Property(registration => registration.Status).IsRequired()
.HasConversion<string>();
entity.Property(r => r.Grade).HasConversion<string>();
entity.Property(r => r.Notes).HasMaxLength(200);
entity.Property(registration => registration.Grade).HasConversion<string>();
entity.Property(registration => registration.Notes).HasMaxLength(200);

// Create unique constraint to prevent duplicate registrations
entity.HasIndex(r => new { r.StudentId, r.CourseId })
entity.HasIndex(registration => new { registration.StudentId, registration.CourseId })
.IsUnique();

// Configure relationships
entity.HasOne(r => r.Student)
.WithMany(s => s.Registrations)
.HasForeignKey(r => r.StudentId)
entity.HasOne(registration => registration.Student)
.WithMany(student => student.Registrations)
.HasForeignKey(registration => registration.StudentId)
.OnDelete(DeleteBehavior.Cascade);

entity.HasOne(r => r.Course)
.WithMany(c => c.Registrations)
.HasForeignKey(r => r.CourseId)
entity.HasOne(registration => registration.Course)
.WithMany(course => course.Registrations)
.HasForeignKey(registration => registration.CourseId)
.OnDelete(DeleteBehavior.Cascade);
});
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public override async Task<int> SaveChangesAsync(CancellationToken cancellationT
private void UpdateTimestamps()
{
var entries = ChangeTracker.Entries()
.Where(e => e.State == EntityState.Added || e.State == EntityState.Modified);
.Where(entry => entry.State == EntityState.Added || entry.State == EntityState.Modified);

var currentTime = DateTime.UtcNow;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,35 @@ public CourseRepository(CourseRegistrationDbContext context) : base(context)
public async Task<Course?> GetWithRegistrationsAsync(Guid courseId)
{
return await _dbSet
.Include(c => c.Registrations)
.ThenInclude(r => r.Student)
.Where(c => c.IsActive)
.FirstOrDefaultAsync(c => c.CourseId == courseId);
.Include(course => course.Registrations)
.ThenInclude(registration => registration.Student)
.Where(course => course.IsActive)
.FirstOrDefaultAsync(course => course.CourseId == courseId);
}

/// <summary>
/// Searches courses by name, instructor, or other criteria asynchronously
/// </summary>
public async Task<IEnumerable<Course>> SearchCoursesAsync(string? searchTerm, string? instructor)
{
var query = _dbSet.Where(c => c.IsActive);
var query = _dbSet.Where(course => course.IsActive);

if (!string.IsNullOrWhiteSpace(searchTerm))
{
var lowerSearchTerm = searchTerm.ToLower();
query = query.Where(c =>
c.CourseName.ToLower().Contains(lowerSearchTerm) ||
(c.Description != null && c.Description.ToLower().Contains(lowerSearchTerm)));
query = query.Where(course =>
course.CourseName.ToLower().Contains(lowerSearchTerm) ||
(course.Description != null && course.Description.ToLower().Contains(lowerSearchTerm)));
}

if (!string.IsNullOrWhiteSpace(instructor))
{
var lowerInstructor = instructor.ToLower();
query = query.Where(c => c.InstructorName.ToLower().Contains(lowerInstructor));
query = query.Where(course => course.InstructorName.ToLower().Contains(lowerInstructor));
}

return await query
.OrderBy(c => c.CourseName)
.OrderBy(course => course.CourseName)
.ToListAsync();
}

Expand All @@ -62,8 +62,8 @@ public async Task<IEnumerable<Course>> SearchCoursesAsync(string? searchTerm, st
public async Task<IEnumerable<Course>> GetActiveCoursesAsync()
{
return await _dbSet
.Where(c => c.IsActive)
.OrderBy(c => c.CourseName)
.Where(course => course.IsActive)
.OrderBy(course => course.CourseName)
.ToListAsync();
}

Expand All @@ -75,10 +75,10 @@ public async Task<IEnumerable<Course>> GetAvailableCoursesAsync()
var currentDate = DateTime.UtcNow;

return await _dbSet
.Include(c => c.Registrations)
.Where(c => c.IsActive && c.StartDate > currentDate)
.OrderBy(c => c.StartDate)
.ThenBy(c => c.CourseName)
.Include(course => course.Registrations)
.Where(course => course.IsActive && course.StartDate > currentDate)
.OrderBy(course => course.StartDate)
.ThenBy(course => course.CourseName)
.ToListAsync();
}

Expand All @@ -92,8 +92,8 @@ public async Task<IEnumerable<Course>> GetCoursesByInstructorAsync(string instru

var lowerInstructorName = instructorName.ToLower();
return await _dbSet
.Where(c => c.IsActive && c.InstructorName.ToLower().Contains(lowerInstructorName))
.OrderBy(c => c.CourseName)
.Where(course => course.IsActive && course.InstructorName.ToLower().Contains(lowerInstructorName))
.OrderBy(course => course.CourseName)
.ToListAsync();
}

Expand All @@ -107,8 +107,8 @@ public override async Task<IEnumerable<Course>> GetPagedAsync(int page, int page
if (pageSize > 100) pageSize = 100;

return await _dbSet
.Where(c => c.IsActive)
.OrderBy(c => c.CourseName)
.Where(course => course.IsActive)
.OrderBy(course => course.CourseName)
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
Expand All @@ -120,8 +120,8 @@ public override async Task<IEnumerable<Course>> GetPagedAsync(int page, int page
public override async Task<Course?> GetByIdAsync(Guid id)
{
return await _dbSet
.Where(c => c.IsActive)
.FirstOrDefaultAsync(c => c.CourseId == id);
.Where(course => course.IsActive)
.FirstOrDefaultAsync(course => course.CourseId == id);
}

/// <summary>
Expand Down
Loading