| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using Diligent.WebAPI.Contracts.DTOs.Pattern;
- 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 PatternExtension
- {
- public static List<Pattern> FilterApplicants(this List<Pattern> query, FilterPatternDto filterPatternDto)
- {
- return query.FilterByDate(filterPatternDto.FromDate, filterPatternDto.ToDate)
- .FilterBySelectionLevels(filterPatternDto.SelectionLevels)
- .ToList();
- }
-
- private static List<Pattern> FilterByDate(this List<Pattern> query, DateTime? fromDate, DateTime? toDate)
- {
- if(fromDate == null && toDate == null) return query;
- if(fromDate == null && toDate != null) return query.Where(x => x.CreatedAt <= toDate).ToList();
- if ((fromDate != null && toDate == null) || (fromDate > toDate)) return query.Where(x => x.CreatedAt >= fromDate).ToList();
- return query.Where(x => x.CreatedAt >= fromDate && x.CreatedAt < toDate).ToList();
- }
-
- private static List<Pattern> FilterBySelectionLevels(this List<Pattern> query, int[]? selectionLevels)
- {
- if (selectionLevels is null)
- {
- return query;
- }
-
- List<Pattern> filteredPatterns = new();
-
- for (int i = 0; i < query.Count; i++)
- {
- for(int j = 0; j < selectionLevels.Length; j++)
- {
- if (query[i].SelectionLevelId == selectionLevels[j])
- {
- filteredPatterns.Add(query[i]);
- break;
- }
- }
- }
-
- return filteredPatterns;
- }
- }
- }
|