Beispiel #1
0
 public SearchValidator(GridTypeModel gridTypeModel)
 {
     RuleForEach(p => p.SearchFields)
     .NotEmpty()
     .Must(p => IsSearchFieldValid(p, gridTypeModel))
     .WithMessage($"You can search only by these {gridTypeModel.TextProperties.ToStringList()} properties.");
 }
        public BaseFilterValidator(GridTypeModel gridTypeModel)
        {
            RuleFor(p => p.Type)
            .IsInEnum();

            RuleFor(p => p.PropertyName)
            .NotEmpty()
            .Must(p => IsFilteringAllowed(gridTypeModel, p))
            .WithMessage($"You can use only {gridTypeModel.PropertyNames.ToStringList()} properties for column.");

            RuleFor(p => p)
            .SetValidator(new BooleanFilterValidator(gridTypeModel))
            .When(t => t.Type == GridFilterType.Boolean);

            RuleFor(p => p)
            .SetValidator(new DateFilterValidator(gridTypeModel))
            .When(t => t.Type == GridFilterType.Date);

            RuleFor(p => p)
            .SetValidator(new ListFilterValidator(gridTypeModel))
            .When(t => t.Type == GridFilterType.List);

            RuleFor(p => p)
            .SetValidator(new NumberFilterValidator(gridTypeModel))
            .When(t => t.Type == GridFilterType.Number);

            RuleFor(p => p)
            .SetValidator(new TextFilterValidator(gridTypeModel))
            .When(t => t.Type == GridFilterType.Text);
        }
Beispiel #3
0
        public NumberFilterValidator(GridTypeModel gridTypeModel)
        {
            RuleFor(p => p.NumberFilterOption)
            .NotNull()
            .IsInEnum();

            RuleFor(p => p.Value)
            .NotNull()
            .NotEmpty()
            .When(p => p.NumberFilterOption != NumberFilterOption.Between);

            RuleFor(p => p.FirstOperand)
            .NotNull()
            .NotEmpty()
            .When(p => p.NumberFilterOption == NumberFilterOption.Between);

            RuleFor(p => p.SecondOperand)
            .NotNull()
            .NotEmpty()
            .When(p => p.NumberFilterOption == NumberFilterOption.Between);

            RuleFor(p => p)
            .Must(p => IsNumericProperty(gridTypeModel, p.PropertyName))
            .WithMessage($"Only numeric properties are allowed for this type of filer {gridTypeModel.NumericProperties.ToStringList()}.");
        }
Beispiel #4
0
 public GroupValidator(GridTypeModel gridTypeModel)
 {
     RuleFor(p => p.PropertyName)
     .NotEmpty()
     .Must(p => IsGroupingAllowed(gridTypeModel, p))
     .WithMessage($"Grouping is not allowed for this property, you can use only {gridTypeModel.PropertyNames.ToStringList()} properties for grouping.");
 }
Beispiel #5
0
        public SummaryValidator(GridTypeModel gridTypeModel)
        {
            RuleFor(p => p.Type)
            .IsInEnum();

            RuleFor(p => p.PropertyName)
            .NotEmpty()
            .Must(p => IsSummaryCalculationAllowed(gridTypeModel, p))
            .WithMessage($"Summary calculation is not allowed for this property, you can use only {gridTypeModel.PropertyNames.ToStringList()} properties for grouping.");
        }
Beispiel #6
0
        public SortingValidator(GridTypeModel gridTypeModel)
        {
            RuleFor(p => p.Direction)
            .IsInEnum();

            RuleFor(p => p.PropertyName)
            .NotEmpty()
            .Must(p => IsSortingAllowed(gridTypeModel, p))
            .WithMessage($"Sorting allowed only for {gridTypeModel.SortablePropertyNames.ToStringList()} properties.");
        }
Beispiel #7
0
        public BooleanFilterValidator(GridTypeModel gridTypeModel)
        {
            RuleFor(p => p.BooleanFilterOption)
            .NotNull()
            .IsInEnum();

            RuleFor(p => p)
            .Must(p => IsBooleanProperty(gridTypeModel, p.PropertyName))
            .WithMessage($"Only boolean properties are allowed for this type of filer {gridTypeModel.BooleanProperties.ToStringList()}.");
        }
Beispiel #8
0
        public ListFilterValidator(GridTypeModel gridTypeModel)
        {
            RuleFor(p => p.ListFilterOption)
            .NotNull()
            .IsInEnum();

            RuleForEach(p => p.Values)
            .NotNull()
            .NotEmpty();

            RuleFor(p => p)
            .Must(p => IsTextProperty(gridTypeModel, p.PropertyName))
            .WithMessage($"Only text properties are allowed for this type of filer {gridTypeModel.TextProperties.ToStringList()}.");
        }
Beispiel #9
0
        public DateFilterValidator(GridTypeModel gridTypeModel)
        {
            RuleFor(p => p.DateFilterOption)
            .NotNull()
            .IsInEnum();

            RuleFor(p => p.SelectedStartDate)
            .NotNull()
            .When(p => p.DateFilterOption == DateFilterOption.DateRange);

            RuleFor(p => p.SelectedEndDate)
            .NotNull()
            .When(p => p.DateFilterOption == DateFilterOption.DateRange);

            RuleFor(p => p)
            .Must(p => IsDateTimeProperty(gridTypeModel, p.PropertyName))
            .WithMessage($"Only date time properties are allowed for this type of filer {gridTypeModel.DateTimeProperties.ToStringList()}.");
        }
Beispiel #10
0
 private static bool IsDateTimeProperty(GridTypeModel gridTypeModel, string propertyName)
 {
     return(gridTypeModel.DateTimeProperties.Contains(propertyName));
 }
 private static bool IsIncludedEntityValid(GridTypeModel gridTypeModel, string includedEntity)
 {
     return(gridTypeModel.IncludedEntities.Contains(includedEntity));
 }
Beispiel #12
0
 private static bool IsSearchFieldValid(string field, GridTypeModel gridTypeModel)
 {
     return(gridTypeModel.TextProperties.Contains(field));
 }
Beispiel #13
0
 private static bool IsSummaryCalculationAllowed(GridTypeModel gridTypeModel, string propertyName)
 {
     return(gridTypeModel.SummarizablePropertyNames.Contains(propertyName));
 }
Beispiel #14
0
 private static bool IsSortingAllowed(GridTypeModel gridTypeModel, string propertyName)
 {
     return(gridTypeModel.SortablePropertyNames.Contains(propertyName));
 }
Beispiel #15
0
 private static bool IsNumericProperty(GridTypeModel gridTypeModel, string propertyName)
 {
     return(gridTypeModel.NumericProperties.Contains(propertyName));
 }