You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ApplicantExtensions.cs 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using static Diligent.WebAPI.Data.Entities.Applicant;
  2. namespace Diligent.WebAPI.Business.Extensions
  3. {
  4. public static class ApplicantExtensions
  5. {
  6. public static IQueryable<Applicant> FilterByExperience(this IQueryable<Applicant> query, int minExperience, int maxExperience)
  7. {
  8. if (minExperience == 0 && maxExperience == 0 || minExperience > maxExperience) return query;
  9. return query.Where(x => x.Experience >= minExperience && x.Experience < maxExperience);
  10. }
  11. public static IQueryable<Applicant> FilterByEmploymentType(this IQueryable<Applicant> query, string? employmentType)
  12. {
  13. if (employmentType == null) return query;
  14. return query.Where(x => x.TypeOfEmployment == Enum.Parse<TypesOfEmployment>(employmentType));
  15. }
  16. public static IQueryable<Applicant> FilterByDateOfApplication(this IQueryable<Applicant> query, DateTime? minDateOfApplication, DateTime? maxDateOfApplication)
  17. {
  18. if (minDateOfApplication == null) return query;
  19. if (minDateOfApplication > maxDateOfApplication) return query;
  20. if (maxDateOfApplication == null) return query.Where(x => x.DateOfApplication >= minDateOfApplication && x.DateOfApplication <= DateTime.Now);
  21. return query.Where(x => x.DateOfApplication >= minDateOfApplication && x.DateOfApplication < maxDateOfApplication);
  22. }
  23. public static List<Applicant> FilterByTechnologies(this List<Applicant> query, string[]? technologies)
  24. {
  25. if (technologies is null)
  26. {
  27. return query;
  28. }
  29. List<Applicant> filteredApplicants = new();
  30. for (int i = 0; i < query.Count; i++)
  31. {
  32. for (int j = 0; j < query[i].TechnologyApplicants.Count; j++)
  33. {
  34. bool s = false;
  35. for (int n = 0; n < technologies.Length; n++)
  36. {
  37. if (query[i].TechnologyApplicants[j].Technology.Name.ToLower() == technologies[n].ToLower())
  38. {
  39. s = true;
  40. break;
  41. }
  42. }
  43. if (s)
  44. {
  45. filteredApplicants.Add(query[i]);
  46. break;
  47. }
  48. }
  49. }
  50. return filteredApplicants;
  51. }
  52. }
  53. }