コード例 #1
0
        /// <summary>
        /// Merges the specified model state.
        /// </summary>
        /// <param name="modelState">State of the model.</param>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="modelType">Type of the model if is a child class.</param>
        /// <param name="autoMapperTypeMap">The auto mapper type map.</param>
        public static void Merge(this ModelStateDictionary modelState, IDictionary dictionary, PropertyInfo modelType, CommonTypeMap autoMapperTypeMap)
        {
            string prefix = modelType != null ? modelType.Name : "";
            var    maps   = autoMapperTypeMap.GetPropertyMaps().Where(p => p.SourceMember != null);

            foreach (var key in dictionary.Keys)
            {
                var    propertyName = maps.FirstOrDefault(p => p.SourceMember.Name == key.ToString());
                string name         = propertyName != null ? propertyName.DestinationProperty.Name : key.ToString();

                modelState.AddModelError((string.IsNullOrEmpty(prefix) ? "" : (prefix + ".")) + name, dictionary[key].ToString());
            }
        }
コード例 #2
0
        /// <summary>
        /// Merges the specified model state.
        /// </summary>
        /// <param name="modelState">State of the model.</param>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="autoMapperTypeMap">The auto mapper type map.</param>
        public static void Merge(this ModelStateDictionary modelState, IDictionary dictionary, CommonTypeMap autoMapperTypeMap)
        {
            var maps = autoMapperTypeMap.GetPropertyMaps().Where(p => p.SourceMember != null);

            foreach (var key in dictionary.Keys)
            {
                var    propertyName = maps.FirstOrDefault(p => p.SourceMember.Name == key.ToString());
                string name         = propertyName != null ? propertyName.DestinationProperty.Name : key.ToString();

                modelState.AddModelError(name, dictionary[key].ToString());
            }
        }