From 75e4a5bf284d49c384f91b3f84bd326bcd5b463d Mon Sep 17 00:00:00 2001 From: DusicaPesic <130140285+DusicaPesic@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:30:58 +0100 Subject: [PATCH 1/2] [Add] SearchExamSlots to ExamSlotController Added implementation of the SearchExamSlots method, which filters exam slots based on the provided criteria, such as exam date, course language, and language level. --- LangLang/Core/Controller/ExamSlotController.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/LangLang/Core/Controller/ExamSlotController.cs b/LangLang/Core/Controller/ExamSlotController.cs index a12108db..0e149e5a 100644 --- a/LangLang/Core/Controller/ExamSlotController.cs +++ b/LangLang/Core/Controller/ExamSlotController.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using static System.Reflection.Metadata.BlobBuilder; namespace LangLang.Core.Controller { @@ -78,5 +79,21 @@ public bool IsExamSlotAvailable(ExamSlot examSlot) return true; } + // Method to search exam slots by tutor and criteria + public List SearchExamSlots(int tutorId, CourseController courses, DateTime examDate, string courseLanguage, LanguageLevel languageLevel) + { + // Retrieve all exam slots created by the specified tutor + List examSlotsByTutor = this.GetExamSlotsByTutor(tutorId, courses); + + // Apply search criteria if they are not null + List filteredExamSlots = examSlotsByTutor.Where(exam => + (examDate == null || exam.ExamDateTime.Date == examDate.Date) && + (courseLanguage == null || courses.GetAllCourses()[exam.CourseId].Language == courseLanguage) && + (languageLevel == null || courses.GetAllCourses()[exam.CourseId].Level == languageLevel) + ).ToList(); + + return filteredExamSlots; + } + } } From 31cd033a79a42415b58cc54065964a2ad5f0f9ea Mon Sep 17 00:00:00 2001 From: DusicaPesic <130140285+DusicaPesic@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:41:16 +0100 Subject: [PATCH 2/2] [Update] Delete method in ExamSlotController Updated Delete method in ExamSlotController to allow deletion only if there are more than 2 weeks before exam date, and to indicate if deletion was allowed (succesful). --- LangLang/Core/Controller/ExamSlotController.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/LangLang/Core/Controller/ExamSlotController.cs b/LangLang/Core/Controller/ExamSlotController.cs index 0e149e5a..0fc7f2c1 100644 --- a/LangLang/Core/Controller/ExamSlotController.cs +++ b/LangLang/Core/Controller/ExamSlotController.cs @@ -28,12 +28,28 @@ public void Add(ExamSlot examSlot) { _examSlots.AddExamSlot(examSlot); } - + /* public void Delete(int examSlotId) { _examSlots.RemoveExamSlot(examSlotId); } + */ + //returns true if removal was allowed (succesful) or false if removal wasn't allowed (unsuccesful) + public bool Delete(int examSlotId) + { + ExamSlot examSlot = _examSlots.GetAllExamSlots()[examSlotId]; + //should use const variable instead of 14 + if ((examSlot.ExamDateTime - DateTime.Now).TotalDays >= 14) + { + _examSlots.RemoveExamSlot(examSlotId); + return true; + } + else + { + return false; + } + } public void Subscribe(IObserver observer) { _examSlots.Subscribe(observer);