Example #1
0
        private IList <ApplicationAnswer> GetAnswers(JobAdView jobAd)
        {
            var answers = new List <ApplicationAnswer>();

            if (jobAd.Integration.ApplicationRequirements != null && jobAd.Integration.ApplicationRequirements.Questions != null)
            {
                foreach (var question in jobAd.Integration.ApplicationRequirements.Questions)
                {
                    // Each question will be sent with the request so find the answer.

                    var value = new GenericModelBinder().BindModel(ControllerContext, new ModelBindingContext {
                        FallbackToEmptyPrefix = true, ValueProvider = ValueProvider, ModelName = "Question" + question.Id
                    });
                    if (question is MultipleChoiceQuestion)
                    {
                        answers.Add(new MultipleChoiceAnswer {
                            Question = question, Value = value == null ? null : value.ToString()
                        });
                    }
                    else
                    {
                        answers.Add(new TextAnswer {
                            Question = question, Value = value == null ? null : value.ToString()
                        });
                    }
                }
            }

            return(answers);
        }
Example #2
0
    public Task <ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
    {
        var serviceProvider = bindingContext.OperationBindingContext.HttpContext.RequestServices;
        var model           = serviceProvider.GetService(bindingContext.ModelType);

        bindingContext.Model = model;
        var binder = new GenericModelBinder();

        return(binder.BindModelAsync(bindingContext));
    }
Example #3
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            // Add List of Roles to ModelBinders
            Type roleModelType = typeof(List <RoleModel>);
            GenericModelBinder modelBinder1 = new GenericModelBinder();

            ModelBinders.Binders.Add(new KeyValuePair <Type, IModelBinder>(roleModelType, modelBinder1));

            // Add List of Ministries to ModelBinders
            Type ministryModelType          = typeof(List <MinistryModel>);
            GenericModelBinder modelBinder2 = new GenericModelBinder();

            ModelBinders.Binders.Add(new KeyValuePair <Type, IModelBinder>(ministryModelType, modelBinder2));
        }