From e618159f37ab12e52e8fd50484c6b024375a3979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=20=C5=A0inik?= Date: Mon, 17 Jun 2024 00:38:32 +0200 Subject: [PATCH] feat: add and fix Search method to accommodate external tutor skills --- .../BusinessLogic/UseCases/TutorService.cs | 23 ++++++++++++++++--- .../TutorReviewPageViewModel.cs | 5 ++-- .../DirectorView/Tabs/TutorReview.xaml.cs | 9 +++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/LangLang/BusinessLogic/UseCases/TutorService.cs b/LangLang/BusinessLogic/UseCases/TutorService.cs index 281eb10..3254532 100644 --- a/LangLang/BusinessLogic/UseCases/TutorService.cs +++ b/LangLang/BusinessLogic/UseCases/TutorService.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System; +using LangLang.Domain.Enums; namespace LangLang.BusinessLogic.UseCases { @@ -53,12 +54,28 @@ public List GetActive() return _tutors.GetActive(); } - public List Search(DateTime date) + public List Search(DateTime date, string? language, Level? level) { + var tutorSkillService = new TutorSkillService(); List allTutors = GetAll(); + return allTutors.Where(tutor => - (date == default || tutor.EmploymentDate.Date == date.Date) && - (tutor.Profile.IsActive == true)).ToList(); + { + bool dateMatches = date == default || tutor.EmploymentDate.Date == date.Date; + + bool isActive = tutor.Profile.IsActive == true; + + bool languageAndLevelMatch = true; + if (!string.IsNullOrEmpty(language) || level.HasValue) + { + List tutorSkills = tutorSkillService.GetByTutor(tutor); + languageAndLevelMatch = tutorSkills.Any(skill => + (string.IsNullOrEmpty(language) || skill.Language.Contains(language, StringComparison.OrdinalIgnoreCase)) && + (!level.HasValue || skill.Level.ToString().Contains(level.Value.ToString(), StringComparison.OrdinalIgnoreCase))); + } + + return dateMatches && isActive && languageAndLevelMatch; + }).ToList(); } public Tutor GetByEmail(string email) diff --git a/LangLang/WPF/ViewModels/TutorViewModels/TutorReviewPageViewModel.cs b/LangLang/WPF/ViewModels/TutorViewModels/TutorReviewPageViewModel.cs index 5b9cbbe..30f6e6b 100644 --- a/LangLang/WPF/ViewModels/TutorViewModels/TutorReviewPageViewModel.cs +++ b/LangLang/WPF/ViewModels/TutorViewModels/TutorReviewPageViewModel.cs @@ -1,5 +1,6 @@  using LangLang.BusinessLogic.UseCases; +using LangLang.Domain.Enums; using LangLang.Domain.Models; using LangLang.WPF.ViewModels.LanguageLevelViewModels; using System; @@ -81,10 +82,10 @@ public void ShowSuccess() MessageBox.Show("Tutor is successfully deleted"); } - public void Search(DateTime employmentDate) + public void Search(DateTime employmentDate, string? language, Level? level) { var tutorService = new TutorService(); - TutorsForReview = tutorService.Search(employmentDate); + TutorsForReview = tutorService.Search(employmentDate, language, level); Update(); } diff --git a/LangLang/WPF/Views/DirectorView/Tabs/TutorReview.xaml.cs b/LangLang/WPF/Views/DirectorView/Tabs/TutorReview.xaml.cs index b4675cd..4cfbce6 100644 --- a/LangLang/WPF/Views/DirectorView/Tabs/TutorReview.xaml.cs +++ b/LangLang/WPF/Views/DirectorView/Tabs/TutorReview.xaml.cs @@ -1,4 +1,5 @@ using LangLang.Domain.Enums; +using LangLang.Domain.Models; using LangLang.WPF.ViewModels.TutorViewModels; using LangLang.WPF.Views.DirectorView.AdditionalWindows; using System; @@ -44,11 +45,17 @@ private void DeleteTutor_Click(object sender, RoutedEventArgs e) private void Search_Click(object sender, RoutedEventArgs e) { DateTime employmentDate = datePickerEmployment.SelectedDate ?? default; - TutorReviewViewModel.Search(employmentDate); + string? language = languagetb.Text; + Level? level = null; + if (levelCB.SelectedValue != null) + level = (Level)levelCB.SelectedValue; + TutorReviewViewModel.Search(employmentDate, language, level); } private void Clear_Click(object sender, RoutedEventArgs e) { + levelCB.SelectedItem = null; + TutorReviewViewModel.SetDataForReview(); TutorReviewViewModel.Update(); }