From 47999efebecb05d1a4c9e2c29244b5a37ee43b62 Mon Sep 17 00:00:00 2001 From: Natasa Kasikovic~ Date: Sun, 28 Apr 2024 14:43:07 +0200 Subject: [PATCH 1/9] [Refactor]: ExamSlot is no longer dependent on a specific course instance --- LangLang/Core/Model/ExamSlot.cs | 114 ++++++++--------------------- LangLang/Core/Model/Overlapable.cs | 8 ++ LangLang/Core/Model/TimeSlot.cs | 26 +++++++ 3 files changed, 66 insertions(+), 82 deletions(-) create mode 100644 LangLang/Core/Model/Overlapable.cs create mode 100644 LangLang/Core/Model/TimeSlot.cs diff --git a/LangLang/Core/Model/ExamSlot.cs b/LangLang/Core/Model/ExamSlot.cs index 436f202a..aae1ba7e 100644 --- a/LangLang/Core/Model/ExamSlot.cs +++ b/LangLang/Core/Model/ExamSlot.cs @@ -1,104 +1,54 @@ using LangLang.Core.Repository.Serialization; using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace LangLang.Core.Model { - public class ExamSlot: ISerializable + public class ExamSlot: ISerializable, Overlapable { - // Private attributes - private int _id; - private int _courseId; - private int _maxStudents; - private DateTime _examDateTime; - private int _numberOfStudents; + public int Id { get; set; } + public string Language { get; set; } + public LanguageLevel Level { get; set; } + + public int TutorId { get; set; } - // Public properties - public int Id - { - get { return _id; } - set { _id = value; } - } + public TimeSlot TimeSlot { get; set; } + public int MaxStudents { get; set; } - public int CourseId - { - get { return _courseId; } - set { _courseId = value; } - } + // NOTE: if possible don't save number of registeredStudents, ask the database. If not, then add attribute. + - public int MaxStudents + public ExamSlot(int id, string language, LanguageLevel level, TimeSlot timeSlot, int maxStudents, int tutorId) { - get { return _maxStudents; } - set { _maxStudents = value; } - } - - public DateTime ExamDateTime - { - get { return _examDateTime; } - set { _examDateTime = value; } - } - - public int NumberOfStudents - { - get { return _numberOfStudents; } - set { _numberOfStudents = value; } - } - - // Constructor - public ExamSlot(int id, int courseId, int maxStudents, DateTime examDateTime, int numberOfStudents) - { - _id = id; - _courseId = courseId; - _maxStudents = maxStudents; - _examDateTime = examDateTime; - _numberOfStudents = numberOfStudents; - } - - public ExamSlot(int id, int courseId, int maxStudents, DateTime examDateTime) - { - _id = id; - _courseId = courseId; - _maxStudents = maxStudents; - _examDateTime = examDateTime; - _numberOfStudents = 0; + Id = id; + Language = language; + Level = Level; + TutorId = tutorId; + TimeSlot = timeSlot; + MaxStudents = maxStudents; } public ExamSlot() { } - // Methods - - // Method to display information about the exam slot - public override string ToString() - { - return $"ID: {_id} | Course: {_courseId.ToString()} | Max Students: {_maxStudents} | Exam Date and Time: {_examDateTime} | Number of Students: {_numberOfStudents}"; - } - - // Method to convert object to CSV format - //returns array of strings representing attributes of ExamSlot object in string form public string[] ToCSV() { - string[] csvValues = - { - _id.ToString(), - _courseId.ToString(), - _maxStudents.ToString(), - _examDateTime.ToString(), - _numberOfStudents.ToString() - }; - return csvValues; + return new string[] { + Id.ToString(), + Language, + Level.ToString(), + TutorId.ToString(), + // TODO: add serialization for timeSlot when implemented + MaxStudents.ToString(), + }; } - // Method to make object from CSV data - //takes array of strings representing ExamSlot object values and sets attributes of object to that values + public void FromCSV(string[] values) { - _id = int.Parse(values[0]); - _courseId = int.Parse(values[1]); - _maxStudents = int.Parse(values[2]); - _examDateTime = DateTime.Parse(values[3]); - _numberOfStudents = int.Parse(values[4]); + Id = int.Parse(values[0]); + Language = values[1]; + Level = (LanguageLevel)Enum.Parse(typeof(LanguageLevel), values[2]); + TutorId = int.Parse(values[3]); + // TODO: add deserialization for timeSlot when implemented + MaxStudents = int.Parse(values[6]); } } } diff --git a/LangLang/Core/Model/Overlapable.cs b/LangLang/Core/Model/Overlapable.cs new file mode 100644 index 00000000..96a19ac1 --- /dev/null +++ b/LangLang/Core/Model/Overlapable.cs @@ -0,0 +1,8 @@ + +namespace LangLang.Core.Model +{ + public interface Overlapable + { + // TODO: implement + } +} diff --git a/LangLang/Core/Model/TimeSlot.cs b/LangLang/Core/Model/TimeSlot.cs new file mode 100644 index 00000000..2073b029 --- /dev/null +++ b/LangLang/Core/Model/TimeSlot.cs @@ -0,0 +1,26 @@ +using System; +using System.Runtime.Serialization; + +namespace LangLang.Core.Model +{ + public class TimeSlot + { + // NOTE: Adapt as needed during implementation + public int Duration { get; set; } + public DateTime time { get; set; } + + public bool OverlappsWith(TimeSlot timeSlot) + { + // TODO: Implement + return false; + } + + public bool IsInFuture() + { + // TODO: Implement + return false; + } + + // TODO: Add serialization methods + } +} From 9004a4475e1722d0b89201d62663fad71c3b798a Mon Sep 17 00:00:00 2001 From: Natasa Kasikovic~ Date: Sun, 28 Apr 2024 16:36:38 +0200 Subject: [PATCH 2/9] [Add] an attribute indicating whether exam registration is possible --- LangLang/Core/Model/ExamSlot.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/LangLang/Core/Model/ExamSlot.cs b/LangLang/Core/Model/ExamSlot.cs index aae1ba7e..c7e31314 100644 --- a/LangLang/Core/Model/ExamSlot.cs +++ b/LangLang/Core/Model/ExamSlot.cs @@ -8,16 +8,15 @@ public class ExamSlot: ISerializable, Overlapable public int Id { get; set; } public string Language { get; set; } public LanguageLevel Level { get; set; } - public int TutorId { get; set; } - public TimeSlot TimeSlot { get; set; } public int MaxStudents { get; set; } + public bool ApplicationPossible { get; set; } // NOTE: if possible don't save number of registeredStudents, ask the database. If not, then add attribute. - public ExamSlot(int id, string language, LanguageLevel level, TimeSlot timeSlot, int maxStudents, int tutorId) + public ExamSlot(int id, string language, LanguageLevel level, TimeSlot timeSlot, int maxStudents, int tutorId, bool applicationPossible) { Id = id; Language = language; @@ -25,6 +24,7 @@ public ExamSlot(int id, string language, LanguageLevel level, TimeSlot timeSlot, TutorId = tutorId; TimeSlot = timeSlot; MaxStudents = maxStudents; + ApplicationPossible = applicationPossible; } public ExamSlot() { } @@ -38,6 +38,7 @@ public string[] ToCSV() TutorId.ToString(), // TODO: add serialization for timeSlot when implemented MaxStudents.ToString(), + ApplicationPossible.ToString() }; } @@ -49,6 +50,7 @@ public void FromCSV(string[] values) TutorId = int.Parse(values[3]); // TODO: add deserialization for timeSlot when implemented MaxStudents = int.Parse(values[6]); + ApplicationPossible = bool.Parse(values[7]); } } } From de75c42a5f02e07778ecf7e8c5ad3f882e7cf0b6 Mon Sep 17 00:00:00 2001 From: Darinka Loncar <149894872+darinkaloncar@users.noreply.github.com> Date: Sun, 28 Apr 2024 13:18:53 -0700 Subject: [PATCH 3/9] [Update] CourseDTO class Code clean up --- LangLang/DTO/CourseDTO.cs | 122 +++++------------- .../View/CourseGUI/CourseCreateWindow.xaml | 2 +- .../View/CourseGUI/CourseUpdateWindow.xaml | 2 +- 3 files changed, 31 insertions(+), 95 deletions(-) diff --git a/LangLang/DTO/CourseDTO.cs b/LangLang/DTO/CourseDTO.cs index a12c5d9b..fb050808 100644 --- a/LangLang/DTO/CourseDTO.cs +++ b/LangLang/DTO/CourseDTO.cs @@ -25,7 +25,7 @@ public class CourseDTO : INotifyPropertyChanged, IDataErrorInfo private List days; private bool online; private int maxStudents; - private DateTime startDateTime; + private DateTime startDate; private bool createdByDirector; private string time; private bool mon; @@ -143,18 +143,18 @@ public string Time } } - public DateTime StartDateTime + public DateTime StartDate { get { - return startDateTime; + return startDate; } set { - if (value != startDateTime) + if (value != startDate) { - startDateTime = value; - OnPropertyChanged("StartDateTime"); + startDate = value; + OnPropertyChanged("StartDate"); } } } @@ -294,10 +294,10 @@ public string this[string columnName] if (timeParts.Length != 2) return "Time format must be HH:mm"; else return ""; } - if (columnName == "StartDateTime") + if (columnName == "StartDate") { - if (startDateTime < DateTime.Now) return "Please enter a valid date. Dates in the past are not allowed."; - if (startDateTime == default) return "Birth date is required"; + if (startDate < DateTime.Now) return "Please enter a valid date. Dates in the past are not allowed."; + if (startDate == default) return "Birth date is required"; else return ""; } if (columnName == "NumberOfWeeks") @@ -313,19 +313,21 @@ public string this[string columnName] return ""; } } + + private string[] _validatedProperties = {"StartDate", "Language", "Level", "NumberOfWeeks", "Time" }; + public string ConcatenatedDays { get { return string.Join(", ", Days); } } - private string[] _validatedProperties = { "StartDateTime", "Language", "Level", "NumberOfWeeks", "Time" }; - // checks if all properties are valid public bool IsValid { get { - if (online == false) + // if the course is held in person add validation for maximal number of student, otherwize remove it + if (online == false) { _validatedProperties = _validatedProperties.Append("MaxStudents").ToArray(); } @@ -345,37 +347,22 @@ public bool IsValid _validatedProperties = newArray; } } - days = new List(); - if (mon) - { - days.Add(DayOfWeek.Monday); - } - if (tue) - { - days.Add(DayOfWeek.Tuesday); - } - if (wed) - { - days.Add(DayOfWeek.Wednesday); - } - if (thu) - { - days.Add(DayOfWeek.Thursday); - } - if (fri) - { - days.Add(DayOfWeek.Friday); - } - if (days.Count == 0) - { - return false; - } + foreach (var property in _validatedProperties) { - if (this[property] != "") - return false; + if (this[property] != "") return false; } + List _days = new List(); + + if (mon) _days.Add(DayOfWeek.Monday); + if (tue) _days.Add(DayOfWeek.Tuesday); + if (wed) _days.Add(DayOfWeek.Wednesday); + if (thu) _days.Add(DayOfWeek.Thursday); + if (fri) _days.Add(DayOfWeek.Friday); + + if(_days.Count == 0) return false; + days = _days; return true; } } @@ -399,7 +386,7 @@ public Course ToCourse() string[] timeParts = time.Split(':'); int hour = int.Parse(timeParts[0]); int minute = int.Parse(timeParts[1]); - return new Course(Id, tutorId, language, level, numberOfWeeks, days, online, maxStudents, new DateTime(startDateTime.Year, startDateTime.Month, startDateTime.Day, hour, minute, 0), createdByDirector); + return new Course(Id, tutorId, language, level, numberOfWeeks, days, online, maxStudents, new DateTime(startDate.Year, startDate.Month, startDate.Day, hour, minute, 0), createdByDirector); } public CourseDTO(Course course) @@ -412,59 +399,8 @@ public CourseDTO(Course course) TutorId = course.TutorId; Days = course.Days; NumberOfStudents = course.NumberOfStudents; - StringBuilder sbDays = new StringBuilder(); - if (Days.Contains(DayOfWeek.Monday)) - { - Mon = true; - sbDays.Append("Mon "); - } - else - { - Mon = false; - } - if (Days.Contains(DayOfWeek.Tuesday)) - { - Tue = true; - sbDays.Append("Tue "); - } - else - { - Tue = false; - } - if (Days.Contains(DayOfWeek.Wednesday)) - { - Wed = true; - sbDays.Append("Wed "); - } - else - { - Wed = false; - } - if (Days.Contains(DayOfWeek.Thursday)) - { - Thu = true; - sbDays.Append("Thu "); - } - else - { - Thu = false; - } - if (Days.Contains(DayOfWeek.Friday)) - { - Fri = true; - sbDays.Append("Fri "); - } - else - { - Fri = false; - } - // Deletes the last white space from stringbuilder - if (sbDays.Length > 0) - { - sbDays.Remove(sbDays.Length - 1, 1); - } - StringDays = sbDays.ToString(); - StartDateTime = course.StartDateTime; + StringDays = ConcatenatedDays; + StartDate = course.StartDateTime; NumberOfWeeks = course.NumberOfWeeks.ToString(); MaxStudents = course.MaxStudents.ToString(); Time = course.StartDateTime.ToString("HH:mm"); diff --git a/LangLang/View/CourseGUI/CourseCreateWindow.xaml b/LangLang/View/CourseGUI/CourseCreateWindow.xaml index e7635ed8..13dbf5d4 100644 --- a/LangLang/View/CourseGUI/CourseCreateWindow.xaml +++ b/LangLang/View/CourseGUI/CourseCreateWindow.xaml @@ -206,7 +206,7 @@