예제 #1
0
        public override void Apply(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            metadata.AdditionalValues["StringLength.MinimumLength"] = attributes.OfType <StringLengthAttribute>().First().MinimumLength;
            metadata.AdditionalValues["StringLength.MaximumLength"] = attributes.OfType <StringLengthAttribute>().First().MaximumLength;

            base.Apply(metadata, attributes, containerType, modelAccessor, modelType, propertyName);
        }
 public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
 {
     if (metadata.IsReadOnly && string.IsNullOrEmpty(metadata.DataTypeName))
     {
         metadata.DataTypeName = "ReadOnly";
     }
 }
 public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
 {
     if (!string.IsNullOrEmpty(metadata.PropertyName) && string.IsNullOrEmpty(metadata.DataTypeName))
     {
         metadata.Watermark = metadata.DisplayName + "...";
     }
 }
 public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
 {
     if (!string.IsNullOrEmpty(metadata.PropertyName) && string.IsNullOrEmpty(metadata.DisplayName))
     {
         metadata.DisplayName = GetStringWithSpace(metadata.PropertyName);
     }
 }
예제 #5
0
 public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable<Attribute> attributes)
 {
   if (metadata.ModelType == typeof(SelectList) && string.IsNullOrEmpty(metadata.DataTypeName))
   {
     metadata.DataTypeName = "SelectList";
   }
 }
        public void Decorate(Attribute attribute, System.Web.Mvc.ModelMetadata modelMetaData)
        {
            Condition.Requires(attribute).IsNotNull();
            Condition.Requires(attribute).IsOfType(typeof(RangeAttribute));

            var rangeLengthttribtue = (RangeAttribute)attribute;

            string minAttribute = null;
            string maxAttribute = null;

            if (rangeLengthttribtue.OperandType == typeof(string))
            {
                minAttribute = "Minlength";
                maxAttribute = "Maxlength";
            }
            else
            {
                minAttribute = "Min";
                maxAttribute = "Max";
            }

            if (minAttribute != null)
            {
                if (rangeLengthttribtue.Minimum != null)
                {
                    modelMetaData.AddAdditionalValueWithValidationMessage(minAttribute, rangeLengthttribtue.Minimum, rangeLengthttribtue);
                }
                if (rangeLengthttribtue.Maximum != null)
                {
                    modelMetaData.AddAdditionalValueWithValidationMessage(maxAttribute, rangeLengthttribtue.Maximum, rangeLengthttribtue);
                }
            }
        }
예제 #7
0
        public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
        {
            var renderModelAttribute = attributes.OfType <RenderModeAttribute>().FirstOrDefault();

            if (renderModelAttribute != null)
            {
                var renderMode = renderModelAttribute.RenderMode;
                switch (renderMode)
                {
                case RenderMode.DisplayModeOnly:
                    metadata.ShowForDisplay = true;
                    metadata.ShowForEdit    = false;
                    break;

                case RenderMode.EditModeOnly:
                    metadata.ShowForDisplay = false;
                    metadata.ShowForEdit    = true;
                    break;

                case RenderMode.Neither:
                    metadata.ShowForDisplay = false;
                    metadata.ShowForEdit    = false;
                    break;
                }
            }
        }
예제 #8
0
 public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
 {
     if (!string.IsNullOrEmpty(metadata.PropertyName) && metadata.PropertyName.ToLower().Contains("password") && string.IsNullOrEmpty(metadata.DataTypeName))
     {
         metadata.DataTypeName = "Password";
     }
 }
        public void Decorate(Attribute attribute, System.Web.Mvc.ModelMetadata modelMetaData)
        {
            Condition.Requires(attribute).IsNotNull();
            string otherProperty;
            ValidationAttribute valAttribute;

            if (attribute is CompareAttribute)
            {
                var compareAttribtue = (CompareAttribute)attribute;
                otherProperty = compareAttribtue.OtherProperty;
                valAttribute  = compareAttribtue;
            }
            else if (attribute is System.Web.Mvc.CompareAttribute)
            {
                var compareAttribtue = (System.Web.Mvc.CompareAttribute)attribute;
                otherProperty = compareAttribtue.OtherProperty;
                valAttribute  = compareAttribtue;
            }
            else
            {
                throw new ArgumentException("attribute type is not a CompareAttribute", "attribute");
            }

            modelMetaData.AddAdditionalValueWithValidationMessage("Match", otherProperty, valAttribute);
        }
예제 #10
0
 public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
 {
     if (!string.IsNullOrEmpty(metadata.PropertyName) && string.IsNullOrEmpty(metadata.DataTypeName) &&
         TextAreaFieldNames.Contains(metadata.PropertyName.ToLower()))
     {
         metadata.DataTypeName = "MultilineText";
     }
 }
        public override void Apply(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            metadata.IsReadOnly = true;

            metadata.ShowForEdit    = false;
            metadata.ShowForDisplay = true;

            base.Apply(metadata, attributes, containerType, modelAccessor, modelType, propertyName);
        }
예제 #12
0
        public void Apply(System.Web.Mvc.ModelMetadata metadata)
        {
            if (metadata.PropertyName != "Id")
            {
                return;
            }

            metadata.DisplayName = "Conventional Display Name";
        }
예제 #13
0
        public void Decorate(Attribute attribute, System.Web.Mvc.ModelMetadata modelMetaData)
        {
            Condition.Requires(attribute).IsNotNull();
            Condition.Requires(attribute).IsOfType(typeof(MinLengthAttribute));

            var minLengthttribtue = (MinLengthAttribute)attribute;

            modelMetaData.AddAdditionalValueWithValidationMessage("Minlength", minLengthttribtue.Length, minLengthttribtue);
        }
예제 #14
0
        public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
        {
            var attribute = attributes.OfType <Render>().FirstOrDefault();

            if (attribute != null)
            {
                metadata.ShowForEdit = ((Render)attribute).ShowForEdit;
            }
        }
예제 #15
0
 public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
 {
     if (metadata.ModelType == typeof(AuditModel))
     {
         if (string.IsNullOrEmpty(metadata.DataTypeName))
         {
             metadata.DataTypeName = "AuditModel";
         }
         metadata.HideSurroundingHtml = true;
     }
 }
 public override IEnumerable <AngularModelValidator> GetValidators(System.Web.Mvc.ModelMetadata metadata)
 {
     if (metadata.ContainerType != null)
     {
         var attrs = GetTypeDescriptor(metadata.ModelType).GetAttributes().OfType <NgDirectiveAttribute>();
         foreach (var attr in attrs)
         {
             yield return(new NgDirectiveAttributeAdapter(metadata, attr));
         }
     }
 }
예제 #17
0
        public static System.Web.Mvc.MvcHtmlString DtxLabelFor <TModel, TValue>
            (this System.Web.Mvc.HtmlHelper <TModel> html,
            System.Linq.Expressions.Expression <System.Func <TModel, TValue> > expression,
            int column = 0, bool ignoreFor = false,
            System.Collections.Generic.IDictionary <string, object> htmlAttributes = null)
        {
            System.Web.Mvc.ModelMetadata modelMetadata =
                System.Web.Mvc.ModelMetadata.FromLambdaExpression(expression, html.ViewData);

            string htmlFieldName =
                System.Web.Mvc.ExpressionHelper.GetExpressionText(expression);

            string labelText =
                modelMetadata.DisplayName ??
                modelMetadata.PropertyName ??
                htmlFieldName.Split('.').Last();

            if (string.IsNullOrEmpty(labelText))
            {
                return(System.Web.Mvc.MvcHtmlString.Empty);
            }

            System.Web.Mvc.TagBuilder label =
                new System.Web.Mvc.TagBuilder("label");

            if (htmlAttributes != null)
            {
                label.MergeAttributes(htmlAttributes);
            }

            if (ignoreFor == false)
            {
                label.Attributes.Add("for",
                                     html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName));
            }

            label.SetInnerText(labelText);

            label.AddCssClass("control-label");

            if ((column >= 1) && (column <= 12))
            {
                label.AddCssClass("col-sm-" + column);
            }

            string labelString =
                label.ToString(System.Web.Mvc.TagRenderMode.Normal);

            var result =
                System.Web.Mvc.MvcHtmlString.Create(labelString);

            return(result);
        }
        public void Decorate(Attribute attribute, System.Web.Mvc.ModelMetadata modelMetaData)
        {
            Condition.Requires(attribute).IsNotNull();
            Condition.Requires(attribute).IsOfType(typeof(StringLengthAttribute));

            var stringLengthttribtue = (StringLengthAttribute)attribute;

            modelMetaData.AddAdditionalValueWithValidationMessage("Maxlength", stringLengthttribtue.MaximumLength, stringLengthttribtue);

            if (stringLengthttribtue.MinimumLength > 0)
            {
                modelMetaData.AddAdditionalValueWithValidationMessage("Minlength", stringLengthttribtue.MinimumLength, stringLengthttribtue);
            }
        }
        public static string GetTemplateForProperty(System.Web.Mvc.ModelMetadata propertyMetadata)
        {
            var templateName = propertyMetadata.TemplateHint ??
                               propertyMetadata.DataTypeName;

            if (templateName == null)
            {
                templateName = TemplateMap.ContainsKey(propertyMetadata.ModelType) ?
                               TemplateMap[propertyMetadata.ModelType] :
                               propertyMetadata.ModelType.Name;
            }

            return("Angular/" + templateName);
        }
예제 #20
0
        public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
        {
            if (metadata.ModelType.Name == "DateTime" &&
                string.IsNullOrEmpty(metadata.DisplayFormatString))
            {
                metadata.DisplayFormatString = "{0:yyyy-MM-dd}";
            }

            if (metadata.ModelType.Name == "DateTime" &&
                string.IsNullOrEmpty(metadata.EditFormatString))
            {
                metadata.EditFormatString = "{0:yyyy-MM-dd}";
            }
        }
예제 #21
0
        public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes)
        {
            if (!string.IsNullOrEmpty(metadata.PropertyName) && string.IsNullOrEmpty(metadata.DisplayName))
            {
                // split ProperCase words
                metadata.DisplayName = metadata.PropertyName.SplitWords();

                // ends with DT, replace with Date
                metadata.DisplayName = metadata.DisplayName != null
          ? Regex.Replace(metadata.DisplayName, "( DT)$", " Date")
          : null;

                // handle language translations here someday!
            }
        }
예제 #22
0
        public static System.Web.Mvc.MvcHtmlString PageModeTextBoxFor <TModel, TValue>
            (this System.Web.Mvc.HtmlHelper <TModel> html,
            System.Linq.Expressions.Expression <Func <TModel, TValue> > expression,
            object htmlAttributes = null, bool readOnly = false)
        {
            System.Web.Mvc.ModelMetadata oModelMetadata =
                System.Web.Mvc.ModelMetadata.FromLambdaExpression(expression, html.ViewData);

            Dictionary <string, object> dynamicAttribute = new Dictionary <string, object>();

            foreach (var prop in htmlAttributes.GetType().GetProperties())
            {
                if (prop.Name == "htmlAttributes")
                {
                    var propValue = prop.GetValue(htmlAttributes, null);
                    foreach (var innerProp in propValue.GetType().GetProperties())
                    {
                        dynamicAttribute.Add(innerProp.Name, innerProp.GetValue(propValue, null));
                    }
                }
                else
                {
                    dynamicAttribute.Add(prop.Name, prop.GetValue(prop));
                }
            }


            if (html.ViewBag.PageMode == "View")
            {
                if (dynamicAttribute.ContainsKey("readonly") == false)
                {
                    dynamicAttribute.Add("readonly", "read-only");
                }
            }



            return(html.TextBoxFor(expression, dynamicAttribute));
        }
예제 #23
0
        /// <summary>
        /// Traduz os metadados.
        /// </summary>
        /// <param name="metadata"></param>
        /// <returns></returns>
        private IList <global::Kendo.Mvc.UI.ModelFieldDescriptor> Translate(System.Web.Mvc.ModelMetadata metadata)
        {
            var result = new List <global::Kendo.Mvc.UI.ModelFieldDescriptor>();

            foreach (var i in metadata.Properties)
            {
                global::Kendo.Mvc.UI.ModelFieldDescriptor field = null;
                object item = null;
                if (i.AdditionalValues.TryGetValue("StateItem", out item))
                {
                    field = new CustomModelFieldDescriptor((Colosoft.Validation.IStatebleItem)item);
                }
                else
                {
                    field = new global::Kendo.Mvc.UI.ModelFieldDescriptor();
                }
                field.Member     = i.PropertyName;
                field.MemberType = i.ModelType;
                field.IsEditable = !i.IsReadOnly;
                result.Add(field);
            }
            return(result);
        }
예제 #24
0
        public void TransformMetadata(System.Web.Mvc.ModelMetadata metadata,
                                      IEnumerable <Attribute> attributes)
        {
            if (!string.IsNullOrEmpty(metadata.PropertyName) && string.IsNullOrEmpty(metadata.DisplayName))
            {
                // field name ends with the hint, will display the hint text
                string[] displayNameHints = { "StartDate", "EndDate", "PublishingDate" };
                bool     transformed      = false;
                foreach (string hint in displayNameHints)
                {
                    if (CanTrimDisplayName(metadata.PropertyName, hint))
                    {
                        metadata.DisplayName = GetStringWithSpaces(hint);
                        transformed          = true;
                        break;
                    }
                }

                if (!transformed)
                {
                    if (metadata.PropertyName.Contains("_"))
                    {
                        metadata.DisplayName = metadata.PropertyName.Replace("_", " ");
                        metadata.DisplayName = GetStringWithSpaces(metadata.DisplayName);
                    }
                    else if (CanTrimDisplayName(metadata.PropertyName, "Title"))
                    {
                        metadata.DisplayName = GetStringWithSpaces(metadata.PropertyName.Replace("Title", ""));
                        metadata.DisplayName = GetStringWithSpaces(metadata.DisplayName);
                    }
                    else
                    {
                        metadata.DisplayName = GetStringWithSpaces(metadata.PropertyName);
                    }
                }
            }
        }
예제 #25
0
        public override void Apply(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            string modelName = modelType.Name;

            if (string.IsNullOrWhiteSpace(metadata.Description))
            {
                if (modelType.IsGenericType)
                {
                    if (typeof(ICollection).IsAssignableFrom(modelType.GetGenericTypeDefinition()))
                    {
                        modelName = modelType.GetGenericArguments()[0].Name;
                    }
                }

                modelName = modelName.Replace("ViewModel", "");
                modelName = modelName.Replace("GridViewModel", "");
                modelName = modelName.Replace("EditViewModel", "");
                modelName = modelName.Replace("AddViewModel", "");

                metadata.Description = modelName.HumanizeCamel();
            }

            base.Apply(metadata, attributes, containerType, modelAccessor, modelType, propertyName);
        }
예제 #26
0
        //public static System.Web.IHtmlString DtxCaptcha
        //	(this System.Web.Mvc.HtmlHelper html,
        //	int labelColumn = 3)
        //{
        //	string result = string.Empty;

        //	if (Settings.Instance.DisplayCaptchaImage)
        //	{
        //		result +=
        //			"<div class=\"form-group\">";

        //		string caption =
        //			Resources.DataDictionary.SecurityCode;

        //		if ((labelColumn >= 1) && (labelColumn <= 12))
        //		{
        //			result +=
        //				$"<label class=\"control-label col-sm-{ labelColumn }\">{ caption }</label>";
        //		}
        //		else
        //		{
        //			result +=
        //				$"<label class=\"control-label\">{ caption }</label>";
        //		}

        //		result +=
        //			$"<div class=\"col-sm-{ 12 - labelColumn }\">";

        //		result +=
        //			html.Captcha(6, MVC.Shared.Views.PartialViews._DisplayCaptchaImage)
        //			.ToHtmlString();

        //		result += "</div>";
        //		result += "</div>";
        //	}

        //	return html.Raw(result);
        //}

        public static System.Web.IHtmlString DtxDisplayNameAndValueFor <TModel, TValue>
            (this System.Web.Mvc.HtmlHelper <TModel> html,
            System.Linq.Expressions.Expression <System.Func <TModel, TValue> > expression,
            Enums.DisplayValueType displayValueType = Enums.DisplayValueType.Undefined,
            int labelColumn = 3,
            string caption  = null
            //System.Web.Mvc.ActionResult actionResult = null
            )
        {
            //System.Web.Mvc.IT4MVCActionResult oT4MVCActionResult = null;

            //if (actionResult != null)
            //{
            //	oT4MVCActionResult =
            //		actionResult as System.Web.Mvc.IT4MVCActionResult;

            //	if (oT4MVCActionResult == null)
            //	{
            //		return null;
            //	}
            //}

            string result = "<div class='row'>";

            System.Web.Mvc.ModelMetadata modelMetadata =
                System.Web.Mvc.ModelMetadata.FromLambdaExpression(expression, html.ViewData);

            // **************************************************
            string labelStyle =
                "background-color: #f5f5f5; color: black; margin: 0px; padding: 4px; border: 1px solid darkgray";

            string htmlFieldName =
                System.Web.Mvc.ExpressionHelper.GetExpressionText(expression);

            if (string.IsNullOrWhiteSpace(caption))
            {
                caption =
                    modelMetadata.DisplayName ??
                    modelMetadata.PropertyName ??
                    htmlFieldName.Split('.').Last();
            }

            result +=
                string.Format("<div class='col-sm-{0}' style='{1}'>",
                              labelColumn, labelStyle);

            result += caption;

            result += "</div>";
            // **************************************************

            result +=
                string.Format("<div class='col-sm-{0}'>", 12 - labelColumn);

            object valueObject =
                modelMetadata.Model;

            string valueString;

            if (valueObject == null)
            {
                valueString =
                    Dtx.Constant.DISPLAY_NULL_VALUE;
            }
            else
            {
                switch (displayValueType)
                {
                case Enums.DisplayValueType.Number:
                {
                    valueString =
                        Convert.Number(valueObject);

                    break;
                }

                case Enums.DisplayValueType.Percent:
                {
                    valueString =
                        Convert.Number(valueObject);

                    valueString +=
                        " " + Resources.DataDictionary.Percent;

                    break;
                }

                case Enums.DisplayValueType.Currency:
                {
                    valueString =
                        Convert.Number(valueObject);

                    valueString +=
                        " " + Resources.DataDictionary.Currency;

                    break;
                }

                case Enums.DisplayValueType.Date:
                {
                    try
                    {
                        System.DateTime dateTime =
                            System.Convert.ToDateTime(valueObject);

                        valueString =
                            Convert.DateTime(dateTime, displayTime: false);
                    }
                    catch (System.Exception ex)
                    {
                        valueString =
                            Dtx.Constant.DISPLAY_NULL_VALUE;

                        //Dtx.Logger.LogError
                        //	(type: typeof(CustomHtmlHelper), exception: ex);
                    }

                    break;
                }

                case Enums.DisplayValueType.DateTime:
                {
                    try
                    {
                        System.DateTime dateTime =
                            System.Convert.ToDateTime(valueObject);

                        valueString =
                            Convert.DateTime(dateTime, displayTime: true);
                    }
                    catch (System.Exception ex)
                    {
                        valueString =
                            Dtx.Constant.DISPLAY_NULL_VALUE;

                        //Dtx.Logger.LogError
                        //	(type: typeof(CustomHtmlHelper), exception: ex);
                    }

                    break;
                }

                case Enums.DisplayValueType.Raw:
                {
                    valueString =
                        html.Raw(valueObject).ToHtmlString();

                    break;
                }

                case Enums.DisplayValueType.Url:
                {
                    valueString =
                        string.Format("<a href='{0}'>{0}</a>", valueObject);

                    break;
                }

                case Enums.DisplayValueType.EmailAddress:
                {
                    valueString =
                        string.Format("<a href='mailto:{0}'>{0}</a>", valueObject);

                    break;
                }

                default:
                {
                    valueString =
                        html.DisplayFor(expression).ToHtmlString();

                    break;
                }
                }
            }

            result += valueString;

            //if (actionResult == null)
            //{
            //	result += valueString;
            //}
            //else
            //{
            //	System.Web.Mvc.UrlHelper oUrlHelper =
            //		new System.Web.Mvc.UrlHelper(html.ViewContext.RequestContext);

            //	//strResult += oUrlHelper.Action
            //	//	(oT4MVCActionResult.Action,
            //	//	oT4MVCActionResult.Controller,
            //	//	oT4MVCActionResult.RouteValueDictionary);

            //	result +=
            //		html.ActionLink(linkText: valueString,
            //		actionName: oT4MVCActionResult.Action,
            //		controllerName: oT4MVCActionResult.Controller,
            //		routeValues: oT4MVCActionResult.RouteValueDictionary,
            //		htmlAttributes: null);
            //}

            result += "	</div>";
            result += "</div>";

            return(html.Raw(result));
        }
예제 #27
0
        public override void Apply(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
        {
            metadata.AdditionalValues["Integer"] = true;

            base.Apply(metadata, attributes, containerType, modelAccessor, modelType, propertyName);
        }
예제 #28
0
 public IEnumerable <System.Web.Mvc.ModelClientValidationRule> GetClientValidationRules(System.Web.Mvc.ModelMetadata metadata, System.Web.Mvc.ControllerContext context)
 {
     return(new[] {
         new System.Web.Mvc.ModelClientValidationStringLengthRule(FormatErrorMessage(metadata.GetDisplayName()), _minCharacters, int.MaxValue)
     });
 }
 public override void Apply(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
 {
     metadata.IsRequired = false;
 }
예제 #30
0
 public override void Apply(System.Web.Mvc.ModelMetadata metadata, IEnumerable <Attribute> attributes, Type containerType, Func <object> modelAccessor, Type modelType, string propertyName)
 {
     metadata.AdditionalValues["CheckBoxOptions.Choices"] = attributes.OfType <CheckBoxOptions>().First().Choices;
     metadata.TemplateHint = "CheckBoxOptions";
     base.Apply(metadata, attributes, containerType, modelAccessor, modelType, propertyName);
 }