-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace DriverTracker.Models | ||
{ | ||
public class LessThanOrEqualToAttribute : ValidationAttribute | ||
{ | ||
private readonly string _dependentProperty; | ||
|
||
public LessThanOrEqualToAttribute(string dependentProperty) | ||
{ | ||
_dependentProperty = dependentProperty; | ||
} | ||
|
||
protected override ValidationResult IsValid(object value, ValidationContext validationContext) | ||
{ | ||
object model = validationContext.ObjectInstance; | ||
|
||
return Convert.ToDecimal(value) > Convert.ToDecimal(model.GetType().GetProperty(_dependentProperty).GetValue(model)) | ||
? new ValidationResult(this.ErrorMessage) | ||
: ValidationResult.Success; | ||
} | ||
} | ||
} |