Class DatabasePropertyValidationAttribute
Allows you to write a formula against properties that are automatically evaluated to validate changes
Inheritance
Inherited Members
Namespace: LemonEdge.API.Attributes.Validation
Assembly: LemonEdge.API.dll
Syntax
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class DatabasePropertyValidationAttribute : DatabaseValidationAttribute
Remarks
For instance you can validate properties using custom scripts like so:
public interface MyItem
{
bool ValidateX { get; set; }
[DatabasePropertyValidation(
//checkOnLamda. Only validate this property if this returns true
"MyItem." + nameof(ValidateX),
//validOnLamda. If returns false then the validation fails and the following message returns why
//This script uses LemonEdge.Core.FormulaFunctionsWithContext. So you can access the Cache, User, and Updater.
//You can also write any c# script, not just a single line formula
"var itemVaue = MyItem.AmountX; return itemValue > 100;",
//message. Reason for validation failure
"AmountX must be greater than 100 if ValidateX is true.")]
Int16 AmountX { get; set; }
}
Constructors
DatabasePropertyValidationAttribute(string, string, string)
Validates this property whenever the item is changed
Declaration
public DatabasePropertyValidationAttribute(string checkOnLamda, string validOnLamda, string message)
Parameters
Type | Name | Description |
---|---|---|
string | checkOnLamda | Only runs the calidOnLamda check if this statement is true, otherwise it returns valid |
string | validOnLamda | valid if this check is true, false otherwise and returns message |
string | message | Returns message if validOnLamda is false |
Properties
TypeId
Have to override this if AllowMultiple is true
Declaration
public override object TypeId { get; }
Property Value
Type | Description |
---|---|
object |
Overrides
Methods
IsValid(object, IEntityUpdater, IReadOnlyCache, UserInfo, ValidationContext)
The validation method to return if the item, and changes, are valid or not
Declaration
protected override Task<ValidationResult> IsValid(object value, IEntityUpdater dbCon, IReadOnlyCache cache, UserInfo user, ValidationContext validationContext)
Parameters
Type | Name | Description |
---|---|---|
object | value | The item to be validated |
IEntityUpdater | dbCon | A connection to the database to use for validation |
IReadOnlyCache | cache | A local cache of current items to speed validation |
UserInfo | user | The current logged in user who made the changes |
ValidationContext | validationContext | The validation context across all changes |
Returns
Type | Description |
---|---|
Task<ValidationResult> | A task holding the validation result |