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

AdExtensions.cs 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 IQueryable<Ad> FilterByExperience(this IQueryable<Ad> query, int minExperience, int maxExperience) =>
  11. minExperience >= maxExperience ? query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience)
  12. : query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience);
  13. public static IQueryable<Ad> FilterByWorkType(this IQueryable<Ad> query, string workHour) =>
  14. workHour.ToLower() == "parttime" ? query.Where(x => x.WorkHour == WorkHours.PartTime) : query.Where(x => x.WorkHour == WorkHours.FullTime);
  15. public static IQueryable<Ad> FilterByEmploymentType(this IQueryable<Ad> query, string employmentType) =>
  16. employmentType.ToLower() == "intership" ? query.Where(x => x.EmploymentType == EmploymentTypes.Intership) : query.Where(x => x.EmploymentType == EmploymentTypes.Work);
  17. public static List<Ad> FilterByTechnologies(this List<Ad> query, string[] technologies)
  18. {
  19. if (technologies.Length == 0)
  20. {
  21. return query;
  22. }
  23. List<Ad> filteredAds = new List<Ad>();
  24. for (int i = 0; i < query.Count(); i++)
  25. {
  26. for (int j = 0; j < query[i].Technologies.Count(); j++)
  27. {
  28. var s = 0;
  29. for (int k = 0; k < technologies.Length; k++)
  30. {
  31. if (query[i].Technologies[j].Name.ToLower() == technologies[k].ToLower())
  32. {
  33. s = 1;
  34. }
  35. }
  36. if (s == 1)
  37. {
  38. filteredAds.Add(query[i]);
  39. break;
  40. }
  41. }
  42. }
  43. return filteredAds;
  44. }
  45. }
  46. }