public void ConfigureModelBinders() { var binder = new DateTimeModelBinder(); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); }
protected void Application_Start() { // Disable ASP.NET MVC version header MvcHandler.DisableMvcResponseHeader = true; // Don't bother looking for the legacy aspx view engine. ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); RouteConfig.RegisterRoutes(RouteTable.Routes); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); var db = new DateTimeModelBinder(); ModelBinders.Binders.Add(typeof(DateTime), db); ModelBinders.Binders.Add(typeof(DateTime?), db); ModelMappings.Initialise(); Roles.CreateRole("Administrators"); Roles.CreateRole("Editors"); Roles.CreateRole("Users"); MongoConfig.SetupIndexes(); }
public async Task ShouldBindDateTimeAsModel(int?year, int?month, int?day, bool isValid) { var formCollection = new FormCollection(new Dictionary <string, StringValues>() { { "Day", day.ToString() }, { "Month", month.ToString() }, { "Year", year.ToString() }, }); var binder = new DateTimeModelBinder(); var vp = new FormValueProvider(BindingSource.Form, formCollection, CultureInfo.CurrentCulture); var context = GetBindingContext(vp, typeof(DateTime)); await binder.BindModelAsync(context); context.ModelState.IsValid.Should().Be(isValid); if (isValid) { var dateValue = (DateTime)context.Result.Model; dateValue.Date.Day.Should().Be(day); dateValue.Date.Month.Should().Be(month); dateValue.Date.Year.Should().Be(year); dateValue.TimeOfDay.Hours.Should().Be(0); dateValue.TimeOfDay.Minutes.Should().Be(0); dateValue.TimeOfDay.Seconds.Should().Be(0); } else { context.ModelState.ErrorCount.Should().Be(1); } }
protected void Application_Start() { Factory.Initialize(); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var binder = new DateTimeModelBinder(new string[] { "dd/MM/yyyy", "d/M/yyyy" }); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); //Important for localize default validation messages DefaultModelBinder.ResourceClassKey = "ValidationMessages"; ClientDataTypeModelValidatorProvider.ResourceClassKey = "ValidationMessages"; //register our decrypter controller factory ControllerBuilder.Current.SetControllerFactory(typeof(DecryptingControllerFactory)); Thread cleanThread = new Thread(() => Util.CleanTempFolder()); cleanThread.Start(); }
protected virtual AbpDateTimeModelBinder CreateAbpDateTimeModelBinder(ModelBinderProviderContext context) { const DateTimeStyles supportedStyles = DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.AdjustToUniversal; var dateTimeModelBinder = new DateTimeModelBinder(supportedStyles, context.Services.GetRequiredService <ILoggerFactory>()); return(new AbpDateTimeModelBinder(context.Services.GetRequiredService <IClock>(), dateTimeModelBinder)); }
protected void Application_Start() { //AreaRegistration.RegisterAllAreas(); //register areas manually for the order //always put the default as the last one //there is a weired behavior for routs Utilities.RegisterArea <CommonAreaRegistration>(RouteTable.Routes, null); Utilities.RegisterArea <AdminAreaRegistration>(RouteTable.Routes, null); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //my initilizers ModelBinders.Binders.Add(typeof(string), new TrimModelBinder()); var binder = new DateTimeModelBinder( LMYFrameWorkMVC.Common.Helpers.Utilites.GetSettingValue(LookUps.SettingsKeys.FullDateFormat), LMYFrameWorkMVC.Common.Helpers.Utilites.GetSettingValue(LookUps.SettingsKeys.DateFormat), LMYFrameWorkMVC.Common.Helpers.Utilites.GetSettingValue(LookUps.SettingsKeys.TimeFormat) ); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); LMYFrameWorkMVC.Web.CommonCode.SignalR.AppHub.Init(); }
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { HttpConfiguration config = GlobalConfiguration.Configuration; config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false; var binder = new DateTimeModelBinder("dd/MM/yyyy"); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); }
public DateTimeModelBinderTests() { context = new ControllerContext(); binder = new DateTimeModelBinder(); binding = new ModelBindingContext(); binding.ModelName = "DateTimeField"; collection = new NameValueCollection(); context.Controller = Substitute.For <ControllerBase>(); binding.ModelMetadata = new DataAnnotationsModelMetadataProvider() .GetMetadataForProperty(null, typeof(AllTypesView), "DateTimeField"); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); var cultureFormat = new CultureInfo("en-AU").DateTimeFormat.ShortDatePattern; var binder = new DateTimeModelBinder(cultureFormat); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); // //var binder = new DateTimeModelBinder(GetCustomDateFormat()); var binder = new DateTimeModelBinder(AppConstant.DATE_TIME_FORMAT); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); }
//public void RegisterAllDependencies() //{ // var routes = HostContainer.GetInstances<IEzCMSRouteRegister>().Distinct(); // foreach (var EzCMSRouteRegister in routes) // { // try // { // Type T = EzCMSRouteRegister.GetType(); // var registration = (AreaRegistration)Activator.CreateInstance(T); // var registrationContext = new AreaRegistrationContext(registration.AreaName, RouteTable.Routes, null); // string areaNamespace = registration.GetType().Namespace; // if (!string.IsNullOrEmpty(areaNamespace)) // registrationContext.Namespaces.Add(areaNamespace + ".*"); // registration.RegisterArea(registrationContext); // } // catch { } // } //} #endregion #region Model Binders public static void RegisterModelBinders() { // Register datetime model binder for time zone convert var dateTimeModelBinder = new DateTimeModelBinder(); ModelBinders.Binders.Add(typeof(DateTime), dateTimeModelBinder); ModelBinders.Binders.Add(typeof(DateTime?), dateTimeModelBinder); // Register timespan model binder for time zone convert var timeSpanModelBinder = new TimeSpanModelBinder(); ModelBinders.Binders.Add(typeof(TimeSpan), timeSpanModelBinder); ModelBinders.Binders.Add(typeof(TimeSpan?), timeSpanModelBinder); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var binder = new DateTimeModelBinder(); System.Web.Mvc.ModelBinders.Binders.Add(typeof(DateTime), binder); System.Web.Mvc.ModelBinders.Binders.Add(typeof(DateTime?), binder); System.Web.Mvc.ModelBinders.Binders.Add(typeof(decimal), new DecimalModelBinder()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ModelBinders.Binders.Add(typeof(ViewModels.BookViewModel), new BookModelBinder()); ModelBinders.Binders.Add(typeof(ViewModels.PublishedBookViewModel), new PublishedBookModelBinder()); // ModelBinders.Binders.Add(typeof(ViewModels.PeriodicalViewModel), new PeriodicalModelBinder()); var binder = new DateTimeModelBinder(CultureFormatsModule.GetCustomDateFormat()); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); DependencyResolverSetter.Inject(); }
public async Task ShouldNotBindIncompleteValueCollectionForDateTime_MissingYear() { var formCollection = new FormCollection(new Dictionary <string, StringValues>() { { "Day", "1" }, { "Month", "12" }, }); var binder = new DateTimeModelBinder(); var vp = new FormValueProvider(BindingSource.Form, formCollection, CultureInfo.CurrentCulture); var context = GetBindingContext(vp, typeof(DateTime)); await binder.BindModelAsync(context); context.Result.Model.Should().BeNull(); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AutoMapperConfiguration.Configure(); var binder = new DateTimeModelBinder("MM/dd/yyyy"); ModelBinders.Binders.Add(typeof(DateTime), binder); ModelBinders.Binders.Add(typeof(DateTime?), binder); Database.SetInitializer(new MigrateDatabaseToLatestVersion <MhotivoContext, Implement.Migrations.Configuration>()); using (var context = new MhotivoContext()) { context.Database.Initialize(true); } }
public async Task TestModelBinderDateTime() { var binder = new DateTimeModelBinder(); var formCollection = new FormCollection( new Dictionary <string, StringValues>() { { "startDate", new StringValues("14.01.2008") }, }); var vp = new FormValueProvider(BindingSource.Form, formCollection, CultureInfo.CurrentCulture); var context = GetBindingContext(vp, typeof(DateTime?)); await binder.BindModelAsync(context); var resultModel = context.Result.Model as DateTime?; Assert.NotNull(resultModel); Assert.True(((DateTime)resultModel).Day == 14); //TODO asserts }
/// <summary> /// Application starting point. /// </summary> protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); GlobalConfiguration.Configure(WebApiConfig.Register); // Migrate database Database.SetInitializer(new MigrateDatabaseToLatestVersion <ApplicationDbContext, Configuration>()); // Handle raygun message RaygunClient.SendingMessage += RaygunClientOnSendingMessage; // Model binders var doubleBinder = new DoubleModelBinder(); var dateTimeBinder = new DateTimeModelBinder("dd.MM.yyyy"); System.Web.Mvc.ModelBinders.Binders.Add(typeof(DateTime), dateTimeBinder); System.Web.Mvc.ModelBinders.Binders.Add(typeof(DateTime?), dateTimeBinder); System.Web.Mvc.ModelBinders.Binders.Add(typeof(double), doubleBinder); }
public DateTimeModelBinder(IClock clock, DateTimeModelBinder dateTimeModelBinder) { _clock = clock; _dateTimeModelBinder = dateTimeModelBinder; }
/// <summary> /// Initializes a new instance of the <see cref="LegacyDateTimeModelBinder"/> class. /// </summary> /// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/> interface.</param> public LegacyDateTimeModelBinder(ILoggerFactory loggerFactory) { _defaultModelBinder = new DateTimeModelBinder(SupportedStyles, loggerFactory); }