コード例 #1
0
        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();
        }
コード例 #2
0
 public CustomDataDisplayFormatAttribute() : base()
 {
     DataFormatString      = $"{{0:{CultureFormatsModule.GetCustomDateFormat()}}}";
     ApplyFormatInEditMode = true;
 }
コード例 #3
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueProvider = bindingContext.ValueProvider;

            string sPeriodicalId = valueProvider.GetValue("Id")?.AttemptedValue;

            int.TryParse(sPeriodicalId, out int periodicalId);

            string name  = (string)valueProvider.GetValue("Name")?.ConvertTo(typeof(string));
            string issn  = (string)valueProvider.GetValue("ISSN")?.ConvertTo(typeof(string));
            bool   isPub = (bool)valueProvider.GetValue("IsPublished")?.ConvertTo(typeof(bool));
            string sType = valueProvider.GetValue("Type.Id")?.AttemptedValue;

            int.TryParse(sType, out int type);
            DateTime foundation = DateTime.ParseExact(valueProvider.GetValue("Foundation").AttemptedValue, CultureFormatsModule.GetCustomDateFormat(), CultureInfo.InvariantCulture);
            string   sPhId      = valueProvider.GetValue("PublishingHouse.Id")?.AttemptedValue;

            int.TryParse(sPhId, out int phId);

            string authorsRaw = valueProvider.GetValue("Authors")?.AttemptedValue;
            List <AuthorViewModel> authors = authorsRaw?.Split(',').
                                             Select(x => { return(int.TryParse(x, out int id) ? new AuthorViewModel {
                    Id = id
                } : null); })
                                             .Where(x => x != null).ToList() ?? new List <AuthorViewModel>();

            PeriodicalViewModel periodical = new PeriodicalViewModel
            {
                Id                 = periodicalId,
                Name               = name,
                ISSN               = issn,
                Foundation         = foundation,
                IsPublished        = isPub,
                PublishingHouse_Id = phId,
                PublishingHouse    = new PublishingHouseViewModel {
                    Id = phId
                },
                Type = new PeriodicalTypeViewModel {
                    Id = type
                },
            };

            return(periodical);
        }
コード例 #4
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueProvider = bindingContext.ValueProvider;

            int?     Id      = (int?)valueProvider.GetValue("Id")?.ConvertTo(typeof(int));
            int      BookId  = (int)valueProvider.GetValue("Book_Id")?.ConvertTo(typeof(int));
            int?     PHId    = (int?)valueProvider.GetValue("PublishingHouse_Id")?.ConvertTo(typeof(int?));
            DateTime DateOfP = DateTime.ParseExact(valueProvider.GetValue("DateOfPublication").AttemptedValue, CultureFormatsModule.GetCustomDateFormat(), CultureInfo.InvariantCulture);
            int      Volume  = (int)valueProvider.GetValue("Volume")?.ConvertTo(typeof(int));



            PublishedBookViewModel book = new PublishedBookViewModel
            {
                Id   = Id.HasValue? Id.Value:0,
                Book = new BookViewModel {
                    Id = BookId
                },
                Book_Id           = BookId,
                DateOfPublication = DateOfP,
                PublishingHouse   = new PublishingHouseViewModel {
                    Id = PHId.HasValue? PHId.Value:0
                },
                PublishingHouse_Id = PHId,
                Volume             = Volume
            };

            return(book);
        }