protected override void AddValidationRules()
{
//Validation rules based on database schema.
// string validate
ValidationRules.AddRule(CommonRules.StringRequired,
new ValidationRuleArgs("CustomerCode", "Customer Code"));
ValidationRules.AddRule(CommonRules.StringMaxLength,
new CommonRules.MaxLengthRuleArgs("CustomerCode", "Customer Code", 128));
ValidationRules.AddRule(CommonRules.NotNull,
new ValidationRuleArgs("OnHoldReason", "On Hold Reason"));
ValidationRules.AddRule(CommonRules.NotNull,
new ValidationRuleArgs("CustomerStatusId", "Customer Status"));
// number validate (int,decimal)
var args = new CommonRules.CompareValueRuleArgs<Int32>("CustomerStatusId", "", 0);
args.Description = "Select Customer Status";
ValidationRules.AddRule(CommonRules.GreaterThanValue<Int32>, args);
// Guid validate
if (this.EntityState != EntityState.Added)
{
var companyArgs = new CommonRules.CompareValueRuleArgs<Guid>("CompanyId", Guid.Empty);
companyArgs.Description = "Select Company";
ValidationRules.AddRule(CommonRules.GreaterThanValue<Guid>, companyArgs);
}
// Guid? validate
var args1 = new CommonRules.CompareValueRuleArgs<Guid?>("VehicleId", "", (Guid?)Guid.Empty);
args1.Description = "Select a vehicle";
ValidationRules.AddRule(CommonRules.GreaterThanOrEqualToValue<Guid>, args1);
// email, allowed empty field
string RegexEmail = @"^(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$";
var email_args = new CommonRules.RegexRuleArgs("email property name", RegexEmail);
email_args.Description = "Email not valid";
ValidationRules.AddRule(CommonRules.RegexIsMatch, email_args);
}
nettier business object validation code
最新推荐文章于 2013-04-03 17:33:56 发布