public IActionResult GenerateUserSpecifiedMixedWorksheet([FromBody] MixedWorksheetParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(ControllerTryCatchBlocks.ReturnBadRequestOnFailedToGenerateExceptionLoggingAllOthers(logger, () =>
            {
                var questionGenerators = new List <IQuestionGenerator <IQuestion> >();
                foreach (var parameter in parameters.Parameters)
                {
                    if (parameter.QuestionType == "quadratic")
                    {
                        var serialisedParameter = JsonConvert.SerializeObject(parameter.Parameter);
                        var quadraticParameter = JsonConvert.DeserializeObject(serialisedParameter, typeof(QuadraticEquationGeneratorParameters));

                        questionGenerators.Add(new QuadraticEquationGenerator(
                                                   randomIntegerGenerator, (QuadraticEquationGeneratorParameters)quadraticParameter));
                    }
                    else if (parameter.QuestionType == "simultaneous")
                    {
                        var serialisedParameter = JsonConvert.SerializeObject(parameter.Parameter);
                        var simultaneousParameter = JsonConvert.DeserializeObject(serialisedParameter, typeof(LinearSimultaneousEquationsGeneratorParameters));

                        questionGenerators.Add(new LinearSimultaneousEquationsGenerator(
                                                   randomIntegerGenerator, (LinearSimultaneousEquationsGeneratorParameters)simultaneousParameter));
                    }
                }
                BuildAndSendPdf(questionGenerators, parameters.EmailAddress.Address);
                return Ok(ModelState);
            },
                                                                                                        BadRequest, parameters));
        }
Esempio n. 2
0
        public IActionResult GetQuadraticEquation([FromBody] QuadraticEquationGeneratorParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(ControllerTryCatchBlocks.ReturnBadRequestOnFailedToGenerateExceptionLoggingAllOthers(logger, () =>
            {
                var equationGenerator = new QuadraticEquationGenerator(randomIntegerGenerator, parameters);
                return Ok(equationGenerator.GenerateQuestionAndAnswer());
            },
                                                                                                        BadRequest, parameters));
        }
        private IActionResult GenerateuserSpecifiedWorksheet <TGeneratorParamaters, TQuestion>(
            WorksheetGeneratorParametersWithCustomParameters <TQuestion, TGeneratorParamaters> worksheetParameters,
            Func <TGeneratorParamaters, IQuestionGenerator <IQuestion> > generatorConstructor)
            where TGeneratorParamaters : IValidatableObject
            where TQuestion : IQuestion
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(ControllerTryCatchBlocks.ReturnBadRequestOnFailedToGenerateExceptionLoggingAllOthers(logger, () =>
            {
                var generators =
                    worksheetParameters.QuestionGeneratorParameters
                    .Select(parameter => generatorConstructor(parameter))
                    .ToList();

                BuildAndSendPdf(generators, worksheetParameters.EmailAddress.Address);
                return Ok(ModelState);
            },
                                                                                                        BadRequest, worksheetParameters));
        }