コード例 #1
0
        /// <summary>
        /// Returns a list of cultures that have any validation errors
        /// </summary>
        /// <param name="modelState"></param>
        /// <param name="localizationService"></param>
        /// <param name="cultureForInvariantErrors">The culture to affiliate invariant errors with</param>
        /// <returns>
        /// A list of cultures that have validation errors. The default culture will be returned for any invariant errors.
        /// </returns>
        internal static IReadOnlyList <string> GetCulturesWithErrors(this System.Web.Http.ModelBinding.ModelStateDictionary modelState,
                                                                     ILocalizationService localizationService, string cultureForInvariantErrors)
        {
            var propertyCultureErrors = modelState.GetCulturesWithPropertyErrors(localizationService, cultureForInvariantErrors);

            //now check the other special culture errors that are
            var genericCultureErrors = modelState.Keys
                                       .Where(x => x.StartsWith("_content_variant_") && x.EndsWith("_"))
                                       .Select(x => x.TrimStart("_content_variant_").TrimEnd("_"))
                                       .Where(x => !x.IsNullOrWhiteSpace())
                                       //if it's marked "invariant" than return the default language, this is because we can only edit invariant properties on the default language
                                       //so errors for those must show up under the default lang.
                                       .Select(x => x == "invariant" ? cultureForInvariantErrors : x)
                                       .WhereNotNull()
                                       .Distinct();

            return(propertyCultureErrors.Union(genericCultureErrors).ToList());
        }