예제 #1
0
 public ValidationResultModel Validate(ValidationCommand validationCommand)
 {
     if (validationCommand == null)
     {
         throw new ArgumentNullException("validationCommand");
     }
     if (!Validators.ContainsKey(validationCommand.ValidatorName))
     {
         return new ValidationResultModel {IsValidatorFound = false};
     }
     try
     {
         var validatorType = Validators[validationCommand.ValidatorName];
         var validator = _objectFactory.Create(validatorType) as IObjectValidator;
         if (validator == null)
         {
             throw new InvalidOperationException("Validator is null.");
         }
         var objectToValidate = _objectConverter.Convert(validationCommand.Value, validator.ValidatedType);
         IList<ValidationFault> result = validator.Validate(objectToValidate);
         return new ValidationResultModel
         {
             ValidationFaults = result,
             IsValidatorFound = true
         };
     }
     catch (Exception ex)
     {
         throw new ServiceException("Can't validate requested object", ex);
     }
 }
예제 #2
0
 public IHttpActionResult Validate([FromUri]string name, [FromBody] object value)
 {
     var request = new ValidationCommand {ValidatorName = name, Value = value};
     var result = _validationService.Validate(request);
     if (result == null || !result.IsValidatorFound)
     {
         return NotFound();
     }
     return Ok(new {faults = result.ValidationFaults, isValid = result.IsValid});
 }