Ejemplo n.º 1
0
 private static void AddClientValidators(DataSetMvcConfiguration config, params IDataSetClientValidator[] clientValidators)
 {
     for (int i = 0; i < clientValidators.Length; i++)
     {
         config.DataSetClientValidators.Add(clientValidators[i]);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds DataSet MVC support.
        /// </summary>
        /// <param name="mvcBuilder">The <see cref="IMvcBuilder"/>.</param>
        /// <param name="configurationExpression">Delegate to configure with <see cref="DataSetMvcConfiguration"/>.</param>
        /// <returns>The <see cref="IMvcBuilder"/> for fluent coding.</returns>
        public static IMvcBuilder AddDataSetMvc(this IMvcBuilder mvcBuilder, Action <DataSetMvcConfiguration> configurationExpression = null)
        {
            var expr   = configurationExpression ?? delegate { };
            var config = new DataSetMvcConfiguration();

            mvcBuilder
            .AddMvcOptions(options => {
                options.ModelValidatorProviders.Add(new DataSetValidatorProvider());
                options.ModelBinderProviders.Insert(0, new DataSetModelBinderProvider());

                config.AddClientValidators(options.ModelBindingMessageProvider);
                expr(config);
            })
            .AddJsonOptions(options => {
                options.JsonSerializerOptions.Converters.Add(new DataSetJsonConverter());
            });

            var services = mvcBuilder.Services;

            services.AddSingleton(config);
            services.TryAddSingleton <DataSetValidationHtmlAttributeProvider, DefaultDataSetValidationHtmlAttributeProvider>();
            services.TryAddSingleton <IDataSetHtmlGenerator, DefaultDataSetHtmlGenerator>();

            return(mvcBuilder);
        }
Ejemplo n.º 3
0
 internal static void AddClientValidators(this DataSetMvcConfiguration config, ModelBindingMessageProvider messageProvider)
 {
     AddClientValidators(config,
                         new MaxLengthClientValidator(),
                         new NumericClientValidator(messageProvider),
                         new RegularExpressionClientValidator(),
                         new RequiredClientValidator(),
                         new StringLengthClientValidator());
 }
Ejemplo n.º 4
0
        public static IDataSetHtmlGenerator GetDataSetHtmlGenerator(Action <DataSetMvcConfiguration> configurationExpression = null)
        {
            var mvcViewOptionsAccessor = new Mock <IOptions <MvcViewOptions> >();

            mvcViewOptionsAccessor.SetupGet(accessor => accessor.Value).Returns(new MvcViewOptions());

            var config = new DataSetMvcConfiguration();

            config.AddClientValidators(new DefaultModelBindingMessageProvider());
            configurationExpression?.Invoke(config);
            var attributeProvider = new DefaultDataSetValidationHtmlAttributeProvider(config);

            return(new DefaultDataSetHtmlGenerator(mvcViewOptionsAccessor.Object, attributeProvider));
        }