From 03073577f0be1690c293595e2d1dd7321ba00832 Mon Sep 17 00:00:00 2001 From: Natasa Kasikovic~ Date: Mon, 29 Apr 2024 12:26:42 +0200 Subject: [PATCH 1/3] [Refactor] remove unused imports and functions --- LangLang/DTO/ExamSlotDTO.cs | 46 ++----------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/LangLang/DTO/ExamSlotDTO.cs b/LangLang/DTO/ExamSlotDTO.cs index 1c134cbc..1bd42f28 100644 --- a/LangLang/DTO/ExamSlotDTO.cs +++ b/LangLang/DTO/ExamSlotDTO.cs @@ -1,19 +1,13 @@ using LangLang.Core.Model; using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Data; using System.Diagnostics; -using System.Linq; -using System.Reflection; -using System.Text; using System.Text.RegularExpressions; -using System.Threading.Tasks; -using System.Xml.Linq; + namespace LangLang.DTO { - public class ExamSlotDTO : INotifyPropertyChanged, IDataErrorInfo + public class ExamSlotDTO : INotifyPropertyChanged { public ExamSlotDTO() { _courseId = -1; @@ -190,40 +184,6 @@ public ExamSlotDTO(ExamSlot examSlot, Course course) this.ExamDateTime = examSlot.ExamDateTime; } - private DateTime ToDateTime(DateTime date, string time) - { - - string[] timeComponents = time.Split(':'); - - if (timeComponents.Length == 2) - { - // Parse hour component - if (int.TryParse(timeComponents[0], out int hours)) - { - // Parse minute component - if (int.TryParse(timeComponents[1], out int minutes)) - { - // Create a new DateTime object with the combined date and time components - DateTime combinedDateTime = new DateTime(date.Year, date.Month, date.Day, hours, minutes, 0); - - } - else - { - Console.WriteLine("Invalid minute component."); - } - } - else - { - Console.WriteLine("Invalid hour component."); - } - } - else - { - Console.WriteLine("Invalid time format."); - } - return DateTime.Now; - } - public ExamSlot ToExamSlot() { string[] timeParts = _time.Split(':'); @@ -232,8 +192,6 @@ public ExamSlot ToExamSlot() return new ExamSlot(Id, _courseId, _maxStudents, new DateTime(_examDate.Year, _examDate.Month, _examDate.Day, hour, minute, 0), 0); } - public string Error => throw new NotImplementedException(); - public event PropertyChangedEventHandler? PropertyChanged; protected virtual void OnPropertyChanged(string name) From cfa72b528c03cd0f69d43d3e09c0009768c708a6 Mon Sep 17 00:00:00 2001 From: DusicaPesic <130140285+DusicaPesic@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:44:37 +0200 Subject: [PATCH 2/3] [UPDATE] ExamSlotDTO class Adjusted ExamSlotDTO class to work with new class attributes. --- LangLang/Core/Model/TimeSlot.cs | 8 +++++- LangLang/DTO/ExamSlotDTO.cs | 44 ++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/LangLang/Core/Model/TimeSlot.cs b/LangLang/Core/Model/TimeSlot.cs index 2073b029..1dd1aad0 100644 --- a/LangLang/Core/Model/TimeSlot.cs +++ b/LangLang/Core/Model/TimeSlot.cs @@ -7,7 +7,13 @@ public class TimeSlot { // NOTE: Adapt as needed during implementation public int Duration { get; set; } - public DateTime time { get; set; } + public DateTime Time { get; set; } + + public TimeSlot(int duration, DateTime time) + { + Duration = duration; + Time = time; + } public bool OverlappsWith(TimeSlot timeSlot) { diff --git a/LangLang/DTO/ExamSlotDTO.cs b/LangLang/DTO/ExamSlotDTO.cs index 1bd42f28..b636d58e 100644 --- a/LangLang/DTO/ExamSlotDTO.cs +++ b/LangLang/DTO/ExamSlotDTO.cs @@ -9,12 +9,10 @@ namespace LangLang.DTO { public class ExamSlotDTO : INotifyPropertyChanged { - public ExamSlotDTO() { - _courseId = -1; - } + public int Id { get; set; } - private int _courseId; + private int _tutorId; private string _language; private LanguageLevel _level; private int _maxStudents; @@ -22,14 +20,15 @@ public ExamSlotDTO() { private string _time; private int _numberOfStudents; private DateTime _examDateTime; + private bool _applicationPossible; - public int CourseId + public int TutorId { - get { return _courseId; } + get { return _tutorId; } set { - _courseId = value; - OnPropertyChanged("CourseId"); + _tutorId = value; + OnPropertyChanged("TutorId"); } } @@ -117,6 +116,16 @@ public DateTime ExamDateTime } } + public bool ApplicationPossible + { + get { return _applicationPossible; } + set + { + _applicationPossible = value; + OnPropertyChanged("ApplicationPossible"); + } + } + private readonly Regex _TimeRegex = new("^(?:[01]\\d|2[0-3]):(?:[0-5]\\d)$"); @@ -171,17 +180,18 @@ public bool IsValid - public ExamSlotDTO(ExamSlot examSlot, Course course) + public ExamSlotDTO(ExamSlot examSlot, LanguageLevel level, string language, int tutorId, int numberOfStudents) { this.Id = examSlot.Id; - this.Language = course.Language; - this.Level = course.Level; + this.Language = language; + this.Level = level; + this.TutorId = tutorId; this.MaxStudents = examSlot.MaxStudents.ToString(); - this.NumberOfStudents = examSlot.NumberOfStudents; - this.CourseId = examSlot.CourseId; - this.ExamDate = examSlot.ExamDateTime.Date; - this.Time = examSlot.ExamDateTime.ToString("HH:mm"); - this.ExamDateTime = examSlot.ExamDateTime; + this.NumberOfStudents = numberOfStudents; + this.ExamDate = examSlot.TimeSlot.Time.Date; + this.Time = examSlot.TimeSlot.Time.ToString("HH:mm"); + this.ExamDateTime = examSlot.TimeSlot.Time; + this.ApplicationPossible = examSlot.ApplicationPossible; } public ExamSlot ToExamSlot() @@ -189,7 +199,7 @@ public ExamSlot ToExamSlot() string[] timeParts = _time.Split(':'); int hour = int.Parse(timeParts[0]); int minute = int.Parse(timeParts[1]); - return new ExamSlot(Id, _courseId, _maxStudents, new DateTime(_examDate.Year, _examDate.Month, _examDate.Day, hour, minute, 0), 0); + return new ExamSlot(Id, _language,_level, new TimeSlot(4,new DateTime(_examDate.Year, _examDate.Month, _examDate.Day, hour, minute, 0)), 0,_tutorId,_applicationPossible); } public event PropertyChangedEventHandler? PropertyChanged; From 25798476fbfc970f602e6f3693ed5afa58311f5d Mon Sep 17 00:00:00 2001 From: DusicaPesic <130140285+DusicaPesic@users.noreply.github.com> Date: Mon, 29 Apr 2024 14:01:57 +0200 Subject: [PATCH 3/3] [UPDATE] ExamSlotDTO --- LangLang/DTO/ExamSlotDTO.cs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/LangLang/DTO/ExamSlotDTO.cs b/LangLang/DTO/ExamSlotDTO.cs index b636d58e..bdb24bef 100644 --- a/LangLang/DTO/ExamSlotDTO.cs +++ b/LangLang/DTO/ExamSlotDTO.cs @@ -18,8 +18,7 @@ public class ExamSlotDTO : INotifyPropertyChanged private int _maxStudents; private DateTime _examDate; private string _time; - private int _numberOfStudents; - private DateTime _examDateTime; + private int _numberStudents; private bool _applicationPossible; public int TutorId @@ -67,7 +66,7 @@ public string MaxStudents if (int.TryParse(value, out int result) && result >= 0) { _maxStudents = result; - //OnPropertyChanged("MaxStudents"); + OnPropertyChanged("MaxStudents"); } else { @@ -87,13 +86,13 @@ public DateTime ExamDate } } - public int NumberOfStudents + public int NumberStudents { - get { return _numberOfStudents; } + get { return _numberStudents; } set { - _numberOfStudents = value; - //OnPropertyChanged("NumberOfStudents"); + _numberStudents = value; + OnPropertyChanged("NumberOfStudents"); } } @@ -107,14 +106,6 @@ public string Time } } - public DateTime ExamDateTime - { - get { return _examDateTime; } - set - { - _examDateTime = value; - } - } public bool ApplicationPossible { @@ -122,7 +113,6 @@ public bool ApplicationPossible set { _applicationPossible = value; - OnPropertyChanged("ApplicationPossible"); } } @@ -180,17 +170,16 @@ public bool IsValid - public ExamSlotDTO(ExamSlot examSlot, LanguageLevel level, string language, int tutorId, int numberOfStudents) + public ExamSlotDTO(ExamSlot examSlot, LanguageLevel level, string language, int tutorId, int numberStudents) { this.Id = examSlot.Id; this.Language = language; this.Level = level; this.TutorId = tutorId; this.MaxStudents = examSlot.MaxStudents.ToString(); - this.NumberOfStudents = numberOfStudents; + this.NumberStudents = numberStudents; this.ExamDate = examSlot.TimeSlot.Time.Date; this.Time = examSlot.TimeSlot.Time.ToString("HH:mm"); - this.ExamDateTime = examSlot.TimeSlot.Time; this.ApplicationPossible = examSlot.ApplicationPossible; } @@ -199,7 +188,7 @@ public ExamSlot ToExamSlot() string[] timeParts = _time.Split(':'); int hour = int.Parse(timeParts[0]); int minute = int.Parse(timeParts[1]); - return new ExamSlot(Id, _language,_level, new TimeSlot(4,new DateTime(_examDate.Year, _examDate.Month, _examDate.Day, hour, minute, 0)), 0,_tutorId,_applicationPossible); + return new ExamSlot(Id, _language,_level, new TimeSlot(4,new DateTime(_examDate.Year, _examDate.Month, _examDate.Day, hour, minute, 0)),_maxStudents,_tutorId,_applicationPossible); } public event PropertyChangedEventHandler? PropertyChanged;