public IList <IInvalidValueInfo> Validate(object entityInstance)
        {
            ErrorSummary errorSummary;

            if (_validatorRunner.IsValid(entityInstance) || (errorSummary = _validatorRunner.GetErrorSummary(entityInstance)) == null)
            {
                return(Enumerable.Empty <IInvalidValueInfo>().ToList());
            }

            var ivs = errorSummary.InvalidProperties
                      .SelectMany(p => from x in errorSummary.GetErrorsForProperty(p) select new InvalidValueInfo(entityInstance.GetType(), p, x))
                      .OfType <IInvalidValueInfo>().ToList();

            return(ivs);
        }
Пример #2
0
        public void Send(Email email)
        {
            if (email == null)
            {
                throw new ArgumentNullException("email");
            }

            if (!_validatorRunner.IsValid(email))
            {
                throw new ValidationException("Email is invalid to send", _validatorRunner.GetErrorSummary(email).ErrorMessages);
            }

            var smtpClient = new SmtpClient();

            using (var message = new MailMessage())
            {
                message.From = new MailAddress(email.FromEmailAddress);
                message.To.Add(email.ToEmailAddress);
                message.Subject    = email.Subject;
                message.Body       = email.Message;
                message.IsBodyHtml = false;

                smtpClient.Send(message);
            }
        }
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            object model = base.BindModel(controllerContext, bindingContext);

            if (model != null && !_runner.IsValid(model))
            {
                AddModelErrors(bindingContext.ModelState, _runner.GetErrorSummary(model));
            }

            return(model);
        }
Пример #4
0
        /// <summary>
        /// Invoked before the interceptor proceeds with the method in
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        protected override void PreProceed(IInvocation invocation)
        {
            MethodInfo method = invocation.Method;

            IValidatorRunner runner = CreateRunner();

            bool isValid = runner.IsValid(invocation);

            if (!isValid)
            {
                ErrorSummary errors = runner.GetErrorSummary(invocation);
                OnInvalidMethod(method, errors);
            }
        }