예제 #1
0
        public async Task <IActionResult> Create(CreateTestTemplatesViewModel createTestTemplatesViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(createTestTemplatesViewModel));
            }
            var testTemplateToCreate = Test.Create(createTestTemplatesViewModel.Name,
                                                   createTestTemplatesViewModel.Description
                                                   , _userId
                                                   , Guid.Parse(createTestTemplatesViewModel.TestTypeId));
            var insertedTest = await _testsRepository.InsertAsync(testTemplateToCreate);

            return(RedirectToAction(nameof(Edit), new { Id = insertedTest.Id }));
        }
예제 #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);
                        }
                    }
                }
            }
        }