Beispiel #1
0
        // ASP.NET Core calls this validate incoming parameters
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var processor = new SortOptionsProcessor <T, TEntity>(OrderBy);

            var validTerms = processor.GetValidTerms().Select(x => x.Name);

            var invalidTerms = processor.GetAllTerms().Select(x => x.Name)
                               .Except(validTerms, StringComparer.OrdinalIgnoreCase);

            foreach (var term in invalidTerms)
            {
                yield return(new ValidationResult(
                                 $"Invalid sort term '{term}'.",
                                 new[] { nameof(OrderBy) }));
            }
        }
Beispiel #2
0
        // The service code will call this to apply these sort options to a database query
        public IQueryable <TEntity> Apply(IQueryable <TEntity> query)
        {
            var processor = new SortOptionsProcessor <T, TEntity>(OrderBy);

            return(processor.Apply(query));
        }