Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Diligent.WebAPI.Business.Extensions
  7. {
  8. public static class AdExtensions
  9. {
  10. public static List<Ad> Filter(this List<Ad> query, AdFilterDto filters) =>
  11. query.FilterByExperience(filters.MinExperience, filters.MaxExperience).FilterByWorkType(filters.WorkHour).FilterByEmploymentType(filters.EmploymentType).ToList().FilterByTechnologies(filters.Technologies);
  12. public static List<Ad> FilterByExperience(this List<Ad> query, int minExperience, int maxExperience) =>
  13. minExperience >= maxExperience ? query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience).ToList()
  14. : query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience).ToList();
  15. public static List<Ad> FilterByWorkType(this List<Ad> query, string workHour) =>
  16. workHour.ToLower() == "parttime" ? query.Where(x => x.WorkHour == WorkHours.PartTime).ToList() : query.Where(x => x.WorkHour == WorkHours.FullTime).ToList();
  17. public static List<Ad> FilterByEmploymentType(this List<Ad> query, string employmentType) =>
  18. employmentType.ToLower() == "intership" ? query.Where(x => x.EmploymentType == EmploymentTypes.Intership).ToList() : query.Where(x => x.EmploymentType == EmploymentTypes.Work).ToList();
  19. public static List<Ad> FilterByTechnologies(this List<Ad> query, string[] technologies)
  20. {
  21. if (technologies == null || technologies.Length == 0)
  22. {
  23. return query;
  24. }
  25. List<Ad> filteredAds = new List<Ad>();
  26. for (int i = 0; i < query.Count(); i++)
  27. {
  28. for (int j = 0; j < query[i].Technologies.Count(); j++)
  29. {
  30. var s = 0;
  31. for (int k = 0; k < technologies.Length; k++)
  32. {
  33. if (query[i].Technologies[j].Name.ToLower() == technologies[k].ToLower())
  34. {
  35. s = 1;
  36. }
  37. }
  38. if (s == 1)
  39. {
  40. filteredAds.Add(query[i]);
  41. break;
  42. }
  43. }
  44. }
  45. return filteredAds;
  46. }
  47. }
  48. }