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

            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(Sort) }));
            }
        }
Esempio n. 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>(Sort);

            return(processor.Apply(query));
        }