Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-exam-application-window-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
anasinik authored Apr 29, 2024
2 parents a6734aa + 5bca650 commit 55e94c4
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 296 deletions.
24 changes: 20 additions & 4 deletions LangLang/Core/Controller/EnrollmentRequestController.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

using LangLang.Core.Model.DAO;
using LangLang.Core.Model.DAO;
using System.Collections.Generic;
using LangLang.Core.Model;
using LangLang.Core.Observer;
using System.Linq;

namespace LangLang.Core.Controller
{
Expand All @@ -16,7 +14,7 @@ public EnrollmentRequestController()
_enrollmentRequests = new EnrollmentRequestDAO();
}

public Dictionary<int, EnrollmentRequest> GetAll()
public List<EnrollmentRequest> GetAll()
{
return _enrollmentRequests.GetAllEnrollmentRequests();
}
Expand Down Expand Up @@ -45,5 +43,23 @@ public List<EnrollmentRequest> GetStudentRequests(int studentId)
{
return _enrollmentRequests.GetStudentRequests(studentId);
}

public bool CancelRequest(EnrollmentRequest enrollmentRequest, CourseController courseController)
{
Course course = courseController.GetById(enrollmentRequest.CourseId);
return _enrollmentRequests.CancelRequest(enrollmentRequest, course);
}

// this method is invoked when the tutor approves the request for the student
public void PauseRequests(int studentId, EnrollmentRequest enrollmentRequest)
{
_enrollmentRequests.PauseRequests(studentId, enrollmentRequest.Id);
}

// this method is invoked when the student complete/withdrawal_from course
public void ResumePausedRequests(int studentId)
{
_enrollmentRequests.ResumePausedRequests(studentId);
}
}
}
11 changes: 8 additions & 3 deletions LangLang/Core/Controller/StudentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void Subscribe(IObserver observer)
_students.Subscribe(observer);
}


public List<Course> GetAvailableCourses(CourseController courseController)
{
return _students.GetAvailableCourses(courseController);
Expand All @@ -52,9 +51,14 @@ public List<ExamSlot> GetAvailableExamSlots(Student student, CourseController co
return _students.GetAvailableExamSlots(student, courseController, examSlotController, enrollmentRequestController);
}

public bool CanModifyInfo(int studentId, EnrollmentRequestController erc)
public bool CanModifyInfo(int studentId, EnrollmentRequestController erController, CourseController courseController)
{
return _students.CanModifyInfo(studentId, erc);
return _students.CanModifyInfo(studentId, erController, courseController);
}

public bool CanRequestEnroll(int id, EnrollmentRequestController erController, CourseController courseController)
{
return _students.CanRequestEnroll(id, erController, courseController);
}

public List<ExamSlot> SearchExamSlotsByStudent(ExamSlotController examSlotController, CourseController courseController, EnrollmentRequestController enrollmentRequestController, int studentId, DateTime examDate, string courseLanguage, LanguageLevel? languageLevel)
Expand All @@ -69,5 +73,6 @@ public List<Course> SearchCoursesByStudent(CourseController courseController, st
List<Course> filteredCourses = courseController.SearchCourses(availableCourses, language, level, startDate, duration, online);
return filteredCourses;
}

}
}
62 changes: 50 additions & 12 deletions LangLang/Core/Model/DAO/EnrollmentRequestDAO.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using LangLang.Core.Observer;
using LangLang.Core.Model.Enums;
using LangLang.Core.Observer;
using LangLang.Core.Repository;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -18,17 +20,17 @@ public EnrollmentRequestDAO()
private int GenerateId()
{
if (_enrollmentRequests.Count == 0) return 0;
return _enrollmentRequests.Count + 1;
return _enrollmentRequests.Keys.Max() + 1;
}

public EnrollmentRequest? GetEnrollmentRequestById(int id)
{
return _enrollmentRequests[id];
}

public Dictionary<int, EnrollmentRequest> GetAllEnrollmentRequests()
public List<EnrollmentRequest> GetAllEnrollmentRequests()
{
return _enrollmentRequests;
return _enrollmentRequests.Values.ToList();
}

public EnrollmentRequest Add(EnrollmentRequest enrollmentRequest)
Expand All @@ -42,19 +44,20 @@ public EnrollmentRequest Add(EnrollmentRequest enrollmentRequest)

public EnrollmentRequest? Update(EnrollmentRequest enrollmentRequest)
{
EnrollmentRequest oldRequest = GetEnrollmentRequestById(enrollmentRequest.Id);
EnrollmentRequest? oldRequest = GetEnrollmentRequestById(enrollmentRequest.Id);
if (oldRequest == null) return null;

oldRequest.Status = enrollmentRequest.Status;

oldRequest.UpdateStatus(enrollmentRequest.Status);
oldRequest.IsCanceled = enrollmentRequest.IsCanceled;
oldRequest.LastModifiedTimestamp = DateTime.Now;
_repository.Save(_enrollmentRequests);
NotifyObservers();
return oldRequest;
}

public EnrollmentRequest? Remove(int id)
{
EnrollmentRequest enrollmentRequest = GetEnrollmentRequestById(id);
EnrollmentRequest? enrollmentRequest = GetEnrollmentRequestById(id);
if (enrollmentRequest == null) return null;

_enrollmentRequests.Remove(enrollmentRequest.Id);
Expand All @@ -65,13 +68,48 @@ public EnrollmentRequest Add(EnrollmentRequest enrollmentRequest)

public List<EnrollmentRequest> GetStudentRequests(int studentId)
{
Dictionary<int, EnrollmentRequest> studentRequests = new();
foreach (EnrollmentRequest enrollmentRequest in GetAllEnrollmentRequests().Values)
List<EnrollmentRequest> studentRequests = new();
foreach (EnrollmentRequest enrollmentRequest in GetAllEnrollmentRequests())
{
if (enrollmentRequest.StudentId == studentId) studentRequests.Add(enrollmentRequest.Id, enrollmentRequest);
if (enrollmentRequest.StudentId == studentId) studentRequests.Add(enrollmentRequest);
}
return studentRequests;
}

// returns true if the cancellation was successful, otherwise false
public bool CancelRequest(EnrollmentRequest enrollmentRequest, Course course)
{
if (course.StartDateTime.Date - DateTime.Now.Date <= TimeSpan.FromDays(7))
return false; // course start date must be at least 7 days away

enrollmentRequest.IsCanceled = true;
return true;
}

public void PauseRequests(int studentId, int acceptedRequestId)
{
var studentRequests = GetStudentRequests(studentId);
foreach (EnrollmentRequest er in studentRequests)
{
if (er.Id == acceptedRequestId)
{
er.UpdateStatus(Status.Accepted);
}
else if (er.Status == Status.Pending && !er.IsCanceled)
{
er.UpdateStatus(Status.Paused);
}
}
return studentRequests.Values.ToList();
}

public void ResumePausedRequests(int studentId)
{
var studentRequests = GetStudentRequests(studentId);
foreach (EnrollmentRequest request in studentRequests)
{
if (request.Status == Status.Paused) request.UpdateStatus(Status.Pending);
}
}

}
}
35 changes: 22 additions & 13 deletions LangLang/Core/Model/DAO/StudentDAO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@
using LangLang.Core.Observer;
using LangLang.Core.Controller;
using LangLang.Core.Model.Enums;
using System;

namespace LangLang.Core.Model.DAO
{
/**
* This class encapsulates a list of Student objects and provides methods
* for adding, updating, deleting, and retrieving Student objects.
* Additionally, this class uses Repository<Student> for loading and saving objects.
**/
public class StudentDAO : Subject
{
private readonly Dictionary<int, Student> _students;
private readonly Repository<Student> _repository;


public StudentDAO()
{
_repository = new Repository<Student>("students.csv");
Expand Down Expand Up @@ -69,7 +65,7 @@ public Student AddStudent(Student student)
NotifyObservers();
return oldStudent;
}

public Student? RemoveStudent(int id, EnrollmentRequestController enrollmentRequestController)
{
Student student = GetStudentById(id);
Expand Down Expand Up @@ -130,15 +126,28 @@ public List<ExamSlot> GetAvailableExamSlots(Student student, CourseController co
return availableExamSlots;
}

public bool CanModifyInfo(int studentId, EnrollmentRequestController erc)
public bool CanModifyInfo(int studentId, EnrollmentRequestController erController, CourseController courseController)
{
List<EnrollmentRequest> studentRequests = erc.GetStudentRequests(studentId);
foreach (EnrollmentRequest request in studentRequests)
{
if (request.Status == Status.Accepted) return false; // TODO: Check if the course is incomplete upon implementing functionality in courseController.
// can modify - student is not currently enrolled in any course and has not applied for any exams
return (CanRequestEnroll(studentId, erController, courseController) && !HasRegisteredForExam());
}

public bool CanRequestEnroll(int id, EnrollmentRequestController erController, CourseController courseController)
{
foreach (EnrollmentRequest er in erController.GetStudentRequests(id))
{
if (er.Status == Status.Accepted && !er.IsCanceled)
{
if (!courseController.IsCompleted(er.Id)) return false;
}
}
return true;
}

public bool HasRegisteredForExam()
{
// TODO: Implement this method once the exam application class is implemented.
return false;
}
}
}
19 changes: 15 additions & 4 deletions LangLang/Core/Model/EnrollmentRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,28 @@ public class EnrollmentRequest : ISerializable
public int Id { get; set; }
public int StudentId { get; set; }
public int CourseId { get; set; }
public Status Status { get; set; }
public Status Status { get; private set; }
public DateTime RequestSentAt { get; set; }
public DateTime LastModifiedTimestamp { get; set; }
public bool IsCanceled { get; set; }

public EnrollmentRequest() { }

public EnrollmentRequest(int id, int studentId, int courseId, Status erStatus, DateTime requestSentAt)
public EnrollmentRequest(int id, int studentId, int courseId, Status status, DateTime requestSentAt)
{
Id = id;
StudentId = studentId;
CourseId = courseId;
Status = erStatus;
Status = status;
RequestSentAt = requestSentAt;
LastModifiedTimestamp = requestSentAt; //Later this will refer to the date of acceptance/rejection/cancellation
IsCanceled = false; // this refers whether the student has canceled request before the course has started
}

public void UpdateStatus(Status status)
{
Status = status;
LastModifiedTimestamp = DateTime.Now;
}

public void FromCSV(string[] values)
Expand All @@ -38,6 +47,7 @@ public void FromCSV(string[] values)
StudentId = int.Parse(values[1]);
CourseId = int.Parse(values[2]);
Status = (Status)Enum.Parse(typeof(Status), values[3]);
IsCanceled = bool.Parse(values[6]);
}

public string[] ToCSV()
Expand All @@ -48,7 +58,8 @@ public string[] ToCSV()
CourseId.ToString(),
Status.ToString(),
RequestSentAt.ToString("yyyy-MM-dd"),
LastModifiedTimestamp.ToString("yyyy-MM-dd")
LastModifiedTimestamp.ToString("yyyy-MM-dd"),
IsCanceled.ToString()
};
}
}
Expand Down
3 changes: 2 additions & 1 deletion LangLang/Core/Model/Enums/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum Status
{
Pending,
Accepted,
Rejected
Rejected,
Paused
}
}
Loading

0 comments on commit 55e94c4

Please sign in to comment.