Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Diligent.WebAPI.Contracts.DTOs.Pattern;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Diligent.WebAPI.Business.Extensions
  8. {
  9. public static class PatternExtension
  10. {
  11. public static List<Pattern> FilterApplicants(this List<Pattern> query, FilterPatternDto filterPatternDto)
  12. {
  13. return query.FilterByDate(filterPatternDto.FromDate, filterPatternDto.ToDate)
  14. .FilterBySelectionLevels(filterPatternDto.SelectionLevels)
  15. .ToList();
  16. }
  17. private static List<Pattern> FilterByDate(this List<Pattern> query, DateTime? fromDate, DateTime? toDate)
  18. {
  19. if(fromDate == null && toDate == null) return query;
  20. if(fromDate == null && toDate != null) return query.Where(x => x.CreatedAt <= toDate).ToList();
  21. if ((fromDate != null && toDate == null) || (fromDate > toDate)) return query.Where(x => x.CreatedAt >= fromDate).ToList();
  22. return query.Where(x => x.CreatedAt >= fromDate && x.CreatedAt < toDate).ToList();
  23. }
  24. private static List<Pattern> FilterBySelectionLevels(this List<Pattern> query, int[]? selectionLevels)
  25. {
  26. if (selectionLevels is null)
  27. {
  28. return query;
  29. }
  30. List<Pattern> filteredPatterns = new();
  31. for (int i = 0; i < query.Count; i++)
  32. {
  33. for(int j = 0; j < selectionLevels.Length; j++)
  34. {
  35. if (query[i].SelectionLevelId == selectionLevels[j])
  36. {
  37. filteredPatterns.Add(query[i]);
  38. break;
  39. }
  40. }
  41. }
  42. return filteredPatterns;
  43. }
  44. }
  45. }