public async Task <IActionResult> Create(CreateExerciseTemplatesViewModel createExerciseTemplatesViewModel)
        {
            if (ModelState.IsValid)
            {
                var exercise = Exercise.Create(createExerciseTemplatesViewModel.Description,
                                               createExerciseTemplatesViewModel.TestTemplateId);
                var insertedExercise = await _exercisesRepository.InsertAsync(exercise);

                return(RedirectToAction(nameof(Create), "AnswerTemplates",
                                        new { testTemplateId = createExerciseTemplatesViewModel.TestTemplateId, exerciseTemplateId = insertedExercise.Id }));
            }

            return(View(createExerciseTemplatesViewModel));
        }
Beispiel #2
0
        public async Task InsertTestTemplateSampleData()
        {
            const int exerciseCount = 2;
            var       teachers      = await _usersRepository.GetAllByRoleName(RoleConstants.TeacherRoleName);

            teachers.Sort((x, emp2) => x.FirstName.CompareTo(emp2.FirstName));
            var testTypes = await _testTypesRepository.GetAllAsync();

            var          multipleChoiceTestType = testTypes[0]; // TODO: obtain multiple choice test type in a safe and extensible way
            const string nameFormat             = "Test{0}";
            const string descriptionFormat      = "Description{0}";


            for (var i = 0; i < teachers.Count; i++)
            {
                for (var x = 0; x < i; x++)
                {
                    var name        = string.Format(nameFormat, x);
                    var description = string.Format(descriptionFormat, x);


                    var testInstace = Test.Create(name, description, teachers[i].Id, multipleChoiceTestType.Id);
                    await _testsRepository.InsertAsync(testInstace);

                    const string exerciseDescriptionFormat = "{1} + {0} = ?";
                    for (var j = 0; j < exerciseCount; j++)
                    {
                        var exerciseDescription = string.Format(exerciseDescriptionFormat, j, x);
                        var exerciseEntity      = Exercise.Create(exerciseDescription, testInstace.Id);

                        var insertedExercise = await _exercisesRepository.InsertAsync(exerciseEntity);

                        const string answerDescriptionFormat = "Answer is {0}";

                        const int answerCount = 2;
                        for (var k = 0; k < answerCount; k++)
                        {
                            const int integerPadding    = 10;
                            var       answerDescription = string.Format(answerDescriptionFormat, integerPadding + k + j + x);
                            var       answerEntiry      = Answer.Create(answerDescription, false, insertedExercise.Id);
                            await _answersRepository.InsertAsync(answerEntiry);
                        }
                    }
                }
            }
        }