public static IBusinessRule FileExists <T>(Expression <Func <T, string> > property) { return(CreateRule.For <T>() .Property(property) .WithRule((item, file) => FileHelper.FileExists(file)) .WithError((item, file) => Validation.FileDoesNotExist(file))); }
private IBusinessRule createTargetHasToBeSetRule() { return(CreateRule.For <EventAssignmentBuilderDTO>() .Property(x => x.ChangedEntityPath) .WithRule((dto, path) => !path.IsNullOrEmpty()) .WithError(AppConstants.Validation.ChangedEntityNotSet)); }
public static IBusinessRule NonEmptyRule <T>(Expression <Func <T, string> > property, string error = Validation.ValueIsRequired) { return(CreateRule.For <T>() .Property(property) .WithRule((o, v) => v.StringIsNotEmpty()) .WithError(error)); }
public static IEnumerable <IBusinessRule> All() { yield return(CreateRule.For <DTOValuePoint>() .Property(x => x.XValue) .WithRule(cannotRepeat) .WithError((dto, timeValue) => AppConstants.Validation.XDimensionColumnMustNotHaveRepeatedValues(dto._tableFormulaDTO.XDisplayName))); }
private IBusinessRule moleuleNameShouldBePresentInProjectRule() { return(CreateRule.For <ApplicationBuilderDTO>() .Property(x => x.MoleculeName) .WithRule((dto, moleculeName) => _getMoleculeNames().Contains(moleculeName)) .WithError(AppConstants.Exceptions.AppliedMoleculeNotInProject)); }
private static IBusinessRule notEmptyTransportNameRule() { return(CreateRule.For <TransporterMoleculeContainerDTO>() .Property(x => x.TransportName) .WithRule((dto, name) => !name.Trim().IsNullOrEmpty()) .WithError(AppConstants.Validation.EmptyTransportName)); }
public static IBusinessRule ParameterIsValid() { return(CreateRule.For <IParameterDTO>() .Property(p => p.Value) .WithRule((p, value) => rulesFor(p, value).IsEmpty) .WithError((p, value) => rulesFor(p, value).Message)); }
public static IBusinessRule ParameterIsValid <TParameterContainer, TProperty>(Expression <Func <TParameterContainer, TProperty> > parameterValue, Func <TParameterContainer, IParameterDTO> parmeterDelegate) { return(CreateRule.For <TParameterContainer>() .Property(parameterValue) .WithRule((parameterContainer, value) => rulesFor(parmeterDelegate(parameterContainer), value).IsEmpty) .WithError((parameterContainer, value) => rulesFor(parmeterDelegate(parameterContainer), value).Message)); }
private IBusinessRule createNonEmptyNameRule() { return(CreateRule.For <FormulaInfoDTO>() .Property(x => x.Name) .WithRule((dto, name) => dto.nameIsValid(name)) .WithError(AppConstants.Validation.EmptyName)); }
private IBusinessRule createRelativeContainerPathNotEmptyRule() { return(CreateRule.For <ApplicationMoleculeBuilderDTO>() .Property(x => x.RelativeContainerPath) .WithRule((dto, path) => !path.IsNullOrEmpty()) .WithError(AppConstants.Validation.RelativeContainerPathNotSet)); }
private static IBusinessRule uniqueTransportNameRule() { return(CreateRule.For <TransporterMoleculeContainerDTO>() .Property(x => x.TransportName) .WithRule((dto, name) => dto.IsNameUnique(name)) .WithError(AppConstants.Validation.TransportNameAllreadyUsed)); }
public static IBusinessRule NotNull <T, U>(Expression <Func <T, U> > property) where U : class { return(CreateRule.For <T>() .Property(property) .WithRule((o, u) => u != null) .WithError(Validation.ValueIsRequired)); }
private IBusinessRule warningRule(string warning) { return(CreateRule.For <IParameter>() .Property(item => item.Value) .WithRule((param, value) => false) .WithError((param, value) => warning)); }
private static IBusinessRule mustHaveAllPreviousPathElementsSet(Expression <Func <StartValueDTO <T>, string> > propertyToCheck) { var index = getPathIndex(propertyToCheck); return(CreateRule.For <StartValueDTO <T> >() .Property(propertyToCheck).WithRule((dto, pathElement) => areAllPreviousPathElementsNonEmpty(dto, pathElement, index)) .WithError((dto, pathElement) => AppConstants.Validation.CannotSetPathElementWhenPreviousElementsAreEmpty)); }
private static IBusinessRule mustNotAlreadyContainStartValue(Expression <Func <StartValueDTO <T>, string> > propertyToCheck) { var index = getPathIndex(propertyToCheck); return(CreateRule.For <StartValueDTO <T> >() .Property(propertyToCheck) .WithRule((dto, pathElement) => noDuplicatesInBuildingBlockRule(dto, pathElement, index)) .WithError((dto, pathElement) => AppConstants.Validation.PathIsIdenticalToExistingPath(newPathWithReplacement(dto, pathElement, index)))); }
private static IBusinessRule createMinLessThanOrEqualToMaxRuleForAxis() => CreateRule.For <Axis>() .Property(axis => axis.Min) .WithRule((axis, value) => !value.HasValue || !axis.Max.HasValue || axis.Max >= value) .WithError((axis, value) => Validation.AxisMinMustBeLessThanOrEqualToAxisMax(axis.Max));
private static IBusinessRule renameMustNotCauseCollision() { return(CreateRule.For <StartValueDTO <T> >() .Property(x => x.Name).WithRule(namedOnlyElementDoesNotExist) .WithError((dto, name) => AppConstants.Validation.NameIsAlreadyUsedInThisContainer(dto.ContainerPath.ToString(), name))); }
private static IBusinessRule createMaxGreaterThanOrEqualToMinRuleForAxis() => CreateRule.For <Axis>() .Property(axis => axis.Max) .WithRule((axis, value) => !value.HasValue || !axis.Min.HasValue || value >= axis.Min) .WithError((axis, value) => Validation.AxisMaxMustBeGreaterThanOrEqualToAxisMin(axis.Min));
private static IBusinessRule createMaxGreaterThanZeroRuleForLogarithmicAxis() => CreateRule.For <Axis>() .Property(axis => axis.Max) .WithRule((axis, value) => !value.HasValue || axis.Scaling != Scalings.Log || value > 0F) .WithError((axis, value) => Validation.LogAxisMaxMustBeGreaterThanZero);