diff --git a/LangLang/Core/Controller/CourseController.cs b/LangLang/Core/Controller/CourseController.cs index 204e750a..00142a5f 100644 --- a/LangLang/Core/Controller/CourseController.cs +++ b/LangLang/Core/Controller/CourseController.cs @@ -35,11 +35,12 @@ public void Subscribe(IObserver observer) _courses.Subscribe(observer); } + // Method checks if the course is valid for updating or canceling public bool IsCourseValid(int courseId) { - Course course = GetAllCourses()[id]; - TimeSpan difference = course.StartDate - DateTime.Now; + Course course = GetAllCourses()[courseId]; + TimeSpan difference = course.StartDateTime - DateTime.Now; return difference.TotalDays < 7; } @@ -47,7 +48,7 @@ public bool IsCourseValid(int courseId) public bool IsCourseAvailable(int courseId) { Course course = GetAllCourses()[courseId]; - TimeSpan difference = course.StartDate - DateTime.Now; + TimeSpan difference = course.StartDateTime - DateTime.Now; if (difference.TotalDays < 7) { if (course.Online) @@ -81,5 +82,20 @@ public Dictionary GetCoursesByTutor(Tutor tutor) return coursesByTutor; } + public Dictionary GetCoursesByTutor(int tutorId) + { + Dictionary coursesByTutor = new Dictionary(); + + foreach (Course course in GetAllCourses().Values) + { + if (course.TutorId == tutorId) + { + coursesByTutor[course.Id] = course; + } + } + + return coursesByTutor; + } + } } \ No newline at end of file diff --git a/LangLang/Core/Model/Course.cs b/LangLang/Core/Model/Course.cs index b408b105..4f836691 100644 --- a/LangLang/Core/Model/Course.cs +++ b/LangLang/Core/Model/Course.cs @@ -20,7 +20,7 @@ public class Course : ISerializable private bool _online; private int _numberOfStudents; private int _maxStudents; - private DateTime _startDate; + private DateTime _startDateTime; // Properties @@ -77,16 +77,16 @@ public int MaxStudents set { _maxStudents = value; } } - public DateTime StartDate + public DateTime StartDateTime { - get { return _startDate; } - set { _startDate = value; } + get { return _startDateTime; } + set { _startDateTime = value; } } // Constructors public Course(int id, int tutorId, string language, LanguageLevel level, int numberOfWeeks, List days, - bool online, int maxStudents, DateTime startDate) + bool online, int maxStudents, DateTime startDateTime) { Id = id; TutorId = tutorId; @@ -97,7 +97,7 @@ public Course(int id, int tutorId, string language, LanguageLevel level, int num Online = online; NumberOfStudents = 0; MaxStudents = maxStudents; - StartDate = startDate; + StartDateTime = startDateTime; } public Course() @@ -118,7 +118,7 @@ public string ToString() sbDays.Remove(sbDays.Length - 1, 1); } - return $"ID: {Id,5} | Language: {Language,20} | Level: {Level,5} | NumberOfWeeks: {NumberOfWeeks,5} | Days: {sbDays, 10} | Online: {Online,5} | NumberOfStudents : {NumberOfStudents,5} | MaxStudents : {MaxStudents,5} | CreationDate : {StartDate,10} |"; + return $"ID: {Id,5} | Language: {Language,20} | Level: {Level,5} | NumberOfWeeks: {NumberOfWeeks,5} | Days: {sbDays, 10} | Online: {Online,5} | NumberOfStudents : {NumberOfStudents,5} | MaxStudents : {MaxStudents,5} | StartDateTime : {StartDateTime,10} |"; } public string[] ToCSV() @@ -145,7 +145,7 @@ public string[] ToCSV() Online.ToString(), NumberOfStudents.ToString(), MaxStudents.ToString(), - StartDate.ToString() + StartDateTime.ToString() }; return csvValues; } @@ -168,7 +168,7 @@ public void FromCSV(string[] values) Online = bool.Parse(values[5]); NumberOfStudents = int.Parse(values[6]); MaxStudents = int.Parse(values[7]); - StartDate = DateTime.Parse(values[8]); + StartDateTime = DateTime.Parse(values[8]); } } }