Exemple #1
0
        //Override IsValid
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var propValue = UiDateTimeUtilities.ChildObjectFromValidationContext(_basePropertyPath,
                                                                                 validationContext);

            var displayName = UiDateTimeUtilities.GetPropertyDisplayNameFromValidationContext(_basePropertyPath,
                                                                                              validationContext);

            if (propValue == null || propValue.ToString().Length == 0)
            {
                var message = FormatErrorMessage(displayName);
                return(new ValidationResult(message));
            }

            //Default return - This means there were no validation error
            return(ValidationResult.Success);
        }
Exemple #2
0
        public static MvcHtmlString UiTimeBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TValue> > expression, object htmlAttributes)
        {
            var propertyPath             = ExpressionHelper.GetExpressionText(expression);
            var attributeKeyPropertyPath = propertyPath.ToLower().Replace(".", "");
            var meta = htmlHelper.ViewData.ModelMetadata;

            var attributes = UiDateTimeUtilities.AddViewDataHtmlAttributes(htmlHelper, propertyPath, new RouteValueDictionary(htmlAttributes));

            var validationAttributes = UiDateTimeUtilities.ChildValidationAttributes(htmlHelper, meta.PropertyName, propertyPath, meta);

            foreach (var attr in validationAttributes)
            {
                attributes.Add(attr.Key.Replace(attributeKeyPropertyPath, ""), attr.Value);
            }

            MvcHtmlString html = System.Web.Mvc.Html.InputExtensions.TextBoxFor(htmlHelper, expression, attributes);

            return(html);
        }
        //Override IsValid
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var propValue   = UiDateTimeUtilities.ChildObjectFromValidationContext(_basePropertyPath, validationContext);
            var displayName = UiDateTimeUtilities.GetPropertyDisplayNameFromValidationContext(_basePropertyPath, validationContext);

            var futureDate = DateTime.UtcNow.AddYears(_maximumYearsInFuture);

            if (propValue != null && !String.IsNullOrWhiteSpace(propValue.ToString()))
            {
                var propDate = DateTime.Parse(propValue.ToString());
                if (propDate > futureDate)
                {
                    var message = FormatErrorMessage(displayName);
                    return(new ValidationResult(message));
                }
            }

            //Default return - This means there were no validation error
            return(ValidationResult.Success);
        }
Exemple #4
0
        //Override IsValid
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            var propValue   = UiDateTimeUtilities.ChildObjectFromValidationContext(_basePropertyPath, validationContext);
            var displayName = UiDateTimeUtilities.GetPropertyDisplayNameFromValidationContext(_basePropertyPath, validationContext);

            try
            {
                if (propValue != null && !String.IsNullOrWhiteSpace(propValue.ToString()))
                {
                    var temp = DateTime.Parse(propValue.ToString());
                }
            }
            catch (FormatException)
            {
                var message = FormatErrorMessage(displayName);
                return(new ValidationResult(message));
            }

            //Default return - This means there were no validation error
            return(ValidationResult.Success);
        }
        //Override IsValid
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value != null)
            {
                var propValue = UiDateTimeUtilities.ChildObjectFromValidationContext(_basePropertyPath, validationContext);

                if (propValue != null && !String.IsNullOrEmpty(propValue.ToString()))
                {
                    var thisDate = DateTime.Parse(propValue.ToString());

                    //Actual comparision
                    if (DateTime.UtcNow.Date < thisDate)
                    {
                        var displayName = UiDateTimeUtilities.GetPropertyDisplayNameFromValidationContext(_basePropertyPath, validationContext);
                        var message     = FormatErrorMessage(displayName);
                        return(new ValidationResult(message));
                    }
                }
            }

            //Default return - This means there were no validation error
            return(ValidationResult.Success);
        }