您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PatternExtension.cs 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. [ExcludeFromCodeCoverage]
  10. public static class PatternExtension
  11. {
  12. public static List<Pattern> FilterApplicants(this List<Pattern> query, FilterPatternDto filterPatternDto)
  13. {
  14. return query.FilterByDate(filterPatternDto.FromDate, filterPatternDto.ToDate)
  15. .FilterBySelectionLevels(filterPatternDto.SelectionLevels)
  16. .ToList();
  17. }
  18. private static List<Pattern> FilterByDate(this List<Pattern> query, DateTime? fromDate, DateTime? toDate)
  19. {
  20. if(fromDate == null && toDate == null) return query;
  21. if(fromDate == null && toDate != null) return query.Where(x => x.CreatedAt <= toDate).ToList();
  22. if ((fromDate != null && toDate == null) || (fromDate > toDate)) return query.Where(x => x.CreatedAt >= fromDate).ToList();
  23. return query.Where(x => x.CreatedAt >= fromDate && x.CreatedAt < toDate).ToList();
  24. }
  25. private static List<Pattern> FilterBySelectionLevels(this List<Pattern> query, int[]? selectionLevels)
  26. {
  27. if (selectionLevels is null)
  28. {
  29. return query;
  30. }
  31. List<Pattern> filteredPatterns = new();
  32. for (int i = 0; i < query.Count; i++)
  33. {
  34. for(int j = 0; j < selectionLevels.Length; j++)
  35. {
  36. if (query[i].SelectionLevelId == selectionLevels[j])
  37. {
  38. filteredPatterns.Add(query[i]);
  39. break;
  40. }
  41. }
  42. }
  43. return filteredPatterns;
  44. }
  45. }
  46. }