| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace Diligent.WebAPI.Business.Extensions
- {
- [ExcludeFromCodeCoverage]
- public static class AdExtensions
- {
- public static List<Ad> Filter(this List<Ad> query, AdFilterDto filters) =>
- query.FilterByExperience(filters.MinExperience, filters.MaxExperience).FilterByWorkType(filters.WorkHour).FilterByEmploymentType(filters.EmploymentType).ToList().FilterByTechnologies(filters.Technologies);
-
- public static List<Ad> FilterByExperience(this List<Ad> query, int minExperience, int maxExperience) =>
- minExperience >= maxExperience ? query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience).ToList()
- : query.Where(x => x.MinimumExperience >= minExperience && x.MinimumExperience <= maxExperience).ToList();
- public static List<Ad> FilterByWorkType(this List<Ad> query, string workHour) =>
- workHour.ToLower() == "parttime" ? query.Where(x => x.WorkHour == WorkHours.PartTime).ToList() : query.Where(x => x.WorkHour == WorkHours.FullTime).ToList();
- public static List<Ad> FilterByEmploymentType(this List<Ad> query, string employmentType) =>
- employmentType.ToLower() == "intership" ? query.Where(x => x.EmploymentType == EmploymentTypes.Intership).ToList() : query.Where(x => x.EmploymentType == EmploymentTypes.Work).ToList();
-
- public static List<Ad> FilterByTechnologies(this List<Ad> query, string[] technologies)
- {
- if (technologies == null || technologies.Length == 0)
- {
- return query;
- }
-
- List<Ad> filteredAds = new List<Ad>();
-
-
- for (int i = 0; i < query.Count(); i++)
- {
- for (int j = 0; j < query[i].Technologies.Count(); j++)
- {
- var s = 0;
-
- for (int k = 0; k < technologies.Length; k++)
- {
- if (query[i].Technologies[j].Name.ToLower() == technologies[k].ToLower())
- {
- s = 1;
- }
- }
-
- if (s == 1)
- {
- filteredAds.Add(query[i]);
- break;
- }
- }
- }
-
- return filteredAds;
- }
- }
- }
|