Skip to content

Commit

Permalink
Merge pull request #475 from kzi-nastava/feat/search-tutors
Browse files Browse the repository at this point in the history
feat: add and fix Search method to accommodate external tutor skills
  • Loading branch information
natasakasikovic authored Jun 16, 2024
2 parents c78618b + e618159 commit 2e84c49
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
23 changes: 20 additions & 3 deletions LangLang/BusinessLogic/UseCases/TutorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System;
using LangLang.Domain.Enums;

namespace LangLang.BusinessLogic.UseCases
{
Expand Down Expand Up @@ -53,12 +54,28 @@ public List<Tutor> GetActive()
return _tutors.GetActive();
}

public List<Tutor> Search(DateTime date)
public List<Tutor> Search(DateTime date, string? language, Level? level)
{
var tutorSkillService = new TutorSkillService();
List<Tutor> 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<LanguageLevel> 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using LangLang.BusinessLogic.UseCases;
using LangLang.Domain.Enums;
using LangLang.Domain.Models;
using LangLang.WPF.ViewModels.LanguageLevelViewModels;
using System;
Expand Down Expand Up @@ -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();
}

Expand Down
9 changes: 8 additions & 1 deletion LangLang/WPF/Views/DirectorView/Tabs/TutorReview.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down

0 comments on commit 2e84c49

Please sign in to comment.