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 @@ -56,16 +56,16 @@ private async Task HandleExceptionAsync(HttpContext context, Exception exception

switch (exception)
{
case ArgumentException argEx:
case ArgumentException argumentException:
response.StatusCode = (int)HttpStatusCode.BadRequest;
errorResponse.Message = "Invalid argument provided";
errorResponse.Errors = new[] { argEx.Message };
errorResponse.Errors = new[] { argumentException.Message };
break;

case InvalidOperationException invOpEx:
case InvalidOperationException invalidOperationException:
response.StatusCode = (int)HttpStatusCode.BadRequest;
errorResponse.Message = "Invalid operation";
errorResponse.Errors = new[] { invOpEx.Message };
errorResponse.Errors = new[] { invalidOperationException.Message };
break;

case UnauthorizedAccessException:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public async Task<IEnumerable<CertificateDto>> GetCertificatesByStudentIdAsync(G
await Task.CompletedTask; // Simulate async operation

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

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

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

public async Task<IEnumerable<CertificateDto>> GetCertificatesByStudentNameAsync(string studentName)
Expand All @@ -118,7 +118,7 @@ public async Task<IEnumerable<CertificateDto>> GetCertificatesByStudentNameAsync
certificates.AddRange(_certificates.Where(c => c.StudentId == student.StudentId));
}

return certificates.Select(MapToDto);
return certificates.Select(MapCertificateToDto);
}

public async Task<CertificateDto> CreateCertificateAsync(CreateCertificateDto createCertificateDto)
Expand All @@ -138,17 +138,17 @@ public async Task<CertificateDto> CreateCertificateAsync(CreateCertificateDto cr
};

_certificates.Add(certificate);
return MapToDto(certificate);
return MapCertificateToDto(certificate);
}

public string GenerateCertificateNumber()
{
var year = DateTime.Now.Year;
var sequence = _certificates.Count + 1;
return $"CERT-{year}-{sequence:D3}";
var issuanceYear = DateTime.UtcNow.Year;
var certificateSequenceNumber = _certificates.Count + 1;
return $"CERT-{issuanceYear}-{certificateSequenceNumber:D3}";
}

private CertificateDto MapToDto(Certificate certificate)
private CertificateDto MapCertificateToDto(Certificate certificate)
{
var student = _students.FirstOrDefault(s => s.StudentId == certificate.StudentId);
var course = _courses.FirstOrDefault(c => c.CourseId == certificate.CourseId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ public async Task<IEnumerable<Course>> SearchCoursesAsync(string? searchTerm, st

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

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

return await query
Expand All @@ -72,11 +72,11 @@ public async Task<IEnumerable<Course>> GetActiveCoursesAsync()
/// </summary>
public async Task<IEnumerable<Course>> GetAvailableCoursesAsync()
{
var currentDate = DateTime.UtcNow;
var currentUtcDateTime = DateTime.UtcNow;

return await _dbSet
.Include(c => c.Registrations)
.Where(c => c.IsActive && c.StartDate > currentDate)
.Where(c => c.IsActive && c.StartDate > currentUtcDateTime)
.OrderBy(c => c.StartDate)
.ThenBy(c => c.CourseName)
.ToListAsync();
Expand All @@ -90,9 +90,9 @@ public async Task<IEnumerable<Course>> GetCoursesByInstructorAsync(string instru
if (string.IsNullOrWhiteSpace(instructorName))
return Enumerable.Empty<Course>();

var lowerInstructorName = instructorName.ToLower();
var normalizedInstructorName = instructorName.ToLower();
return await _dbSet
.Where(c => c.IsActive && c.InstructorName.ToLower().Contains(lowerInstructorName))
.Where(c => c.IsActive && c.InstructorName.ToLower().Contains(normalizedInstructorName))
.OrderBy(c => c.CourseName)
.ToListAsync();
}
Expand Down
34 changes: 17 additions & 17 deletions frontend/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ function initializeForm() {
addCourseForm.addEventListener('submit', handleFormSubmit);

// Instructor name validation (letters, spaces, periods only)
document.getElementById('instructorName').addEventListener('input', function(e) {
const value = e.target.value;
document.getElementById('instructorName').addEventListener('input', function(event) {
const value = event.target.value;
const validPattern = /^[a-zA-Z\s.]*$/;

if (!validPattern.test(value)) {
e.target.value = value.replace(/[^a-zA-Z\s.]/g, '');
event.target.value = value.replace(/[^a-zA-Z\s.]/g, '');
}
});

Expand All @@ -80,8 +80,8 @@ function initializeForm() {
}

// Form Submission Handler
async function handleFormSubmit(e) {
e.preventDefault();
async function handleFormSubmit(event) {
event.preventDefault();

if (!validateForm()) {
return;
Expand Down Expand Up @@ -252,8 +252,8 @@ function clearAllErrors() {
const errorElements = document.querySelectorAll('.error-message');
const inputElements = document.querySelectorAll('.form-input, .form-textarea');

errorElements.forEach(el => el.textContent = '');
inputElements.forEach(el => el.classList.remove('error'));
errorElements.forEach(errorElement => errorElement.textContent = '');
inputElements.forEach(inputElement => inputElement.classList.remove('error'));
}

function displayValidationErrors(errors) {
Expand Down Expand Up @@ -284,19 +284,19 @@ function mapFieldName(apiFieldName) {
}

// UI State Functions
function setSubmitButton(loading, text) {
submitBtn.disabled = loading;
submitText.textContent = text;
function setSubmitButton(isLoading, buttonText) {
submitBtn.disabled = isLoading;
submitText.textContent = buttonText;

if (loading) {
submitBtn.innerHTML = `<i class="fas fa-spinner fa-spin"></i> ${text}`;
if (isLoading) {
submitBtn.innerHTML = `<i class="fas fa-spinner fa-spin"></i> ${buttonText}`;
} else {
submitBtn.innerHTML = `<i class="fas fa-plus"></i> ${text}`;
submitBtn.innerHTML = `<i class="fas fa-plus"></i> ${buttonText}`;
}
}

function showLoading(show) {
loadingOverlay.classList.toggle('hidden', !show);
function showLoading(isVisible) {
loadingOverlay.classList.toggle('hidden', !isVisible);
}

// Modal Functions
Expand Down Expand Up @@ -863,8 +863,8 @@ function applyFilters() {
let filteredRegistrations = allRegistrations;

if (statusFilter !== '') {
filteredRegistrations = filteredRegistrations.filter(reg =>
reg.status.toString() === statusFilter
filteredRegistrations = filteredRegistrations.filter(registration =>
registration.status.toString() === statusFilter
);
}

Expand Down
Loading