Skip to content

Commit

Permalink
Merge pull request #83 from kzi-nastava/feat/SearchExamSlots
Browse files Browse the repository at this point in the history
Added SearchExamSlots method and updated Delete method in ExamSlotController
  • Loading branch information
darinkaloncar authored Mar 30, 2024
2 parents 82f4cde + 31cd033 commit eb38fa3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion LangLang/Core/Controller/ExamSlotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Reflection.Metadata.BlobBuilder;

namespace LangLang.Core.Controller
{
Expand All @@ -27,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);
Expand Down Expand Up @@ -78,5 +95,21 @@ public bool IsExamSlotAvailable(ExamSlot examSlot)
return true;
}

// Method to search exam slots by tutor and criteria
public List<ExamSlot> SearchExamSlots(int tutorId, CourseController courses, DateTime examDate, string courseLanguage, LanguageLevel languageLevel)
{
// Retrieve all exam slots created by the specified tutor
List<ExamSlot> examSlotsByTutor = this.GetExamSlotsByTutor(tutorId, courses);

// Apply search criteria if they are not null
List<ExamSlot> filteredExamSlots = examSlotsByTutor.Where(exam =>
(examDate == null || exam.ExamDateTime.Date == examDate.Date) &&

Check warning on line 106 in LangLang/Core/Controller/ExamSlotController.cs

View workflow job for this annotation

GitHub Actions / build

The result of the expression is always 'false' since a value of type 'DateTime' is never equal to 'null' of type 'DateTime?'
(courseLanguage == null || courses.GetAllCourses()[exam.CourseId].Language == courseLanguage) &&
(languageLevel == null || courses.GetAllCourses()[exam.CourseId].Level == languageLevel)

Check warning on line 108 in LangLang/Core/Controller/ExamSlotController.cs

View workflow job for this annotation

GitHub Actions / build

The result of the expression is always 'false' since a value of type 'LanguageLevel' is never equal to 'null' of type 'LanguageLevel?'
).ToList();

return filteredExamSlots;
}

}
}

0 comments on commit eb38fa3

Please sign in to comment.