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); }
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()}."); }
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."); }
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."); }
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."); }
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()}."); }
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()}."); }
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()}."); }
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)); }
private static bool IsSearchFieldValid(string field, GridTypeModel gridTypeModel) { return(gridTypeModel.TextProperties.Contains(field)); }
private static bool IsSummaryCalculationAllowed(GridTypeModel gridTypeModel, string propertyName) { return(gridTypeModel.SummarizablePropertyNames.Contains(propertyName)); }
private static bool IsSortingAllowed(GridTypeModel gridTypeModel, string propertyName) { return(gridTypeModel.SortablePropertyNames.Contains(propertyName)); }
private static bool IsNumericProperty(GridTypeModel gridTypeModel, string propertyName) { return(gridTypeModel.NumericProperties.Contains(propertyName)); }