Class DatabaseClassValidationAttribute
Allows you to create class level validation, instead of individual field level, that runs when directly connected to the database only
Inheritance
Inherited Members
Namespace: LemonEdge.API.Attributes.Validation
Assembly: LemonEdge.API.dll
Syntax
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Interface, Inherited = false, AllowMultiple = true)]
public class DatabaseClassValidationAttribute : DatabaseValidationAttribute
Remarks
You can mark this attribute against a class, referring to a custom validation like so:
public interface IMyClass { }
[DatabaseClassValidation(typeof(MyCustomValidation), nameof(MyCustomValidation.test))]
public class MyClass : IMyClass
{
}
public static class MyCustomValidation
{
public static Task<ValidationResult> ValidateMyClass(IMyClass item, LemonEdge.Core.IEntityUpdater dbCon, LemonEdge.Entities.IReadOnlyCache cache, LemonEdge.API.Core.UserInfo user, ValidationContext validationContext)
{
//Custom checks here
return Task.FromResult(ValidationResult.Success);
}
}
Constructors
DatabaseClassValidationAttribute(Type, string)
Creates a new DatabaseClass validation attribute that specifies a static method on the specified class to use to validate this class
Declaration
public DatabaseClassValidationAttribute(Type validationClass, string classFunctionName)
Parameters
Type | Name | Description |
---|---|---|
Type | validationClass | The class that holds the method used for validating this class |
string | classFunctionName | The static method name of signature static Task<TResult> IsValid(T value, IEntityUpdater dbCon, IReadOnlyCache cache, UserInfo user, ValidationContext validationContext) |
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 |