Exemple #1
0
        public async Task <ICommandResult <int> > HandleAsync(ExamPreCreateCommand command)
        {
            var exam = new Exam()
            {
                CreatedById = command.CreatedById,
                CourseId    = command.CourseId,
                DueDate     = DateTime.Now.AddDays(30),
                Finalized   = false,
                Name        = "New exam",
                TimeNeeded  = 3600
            };

            await _context.Exam.AddAsync(exam);

            await _context.SaveChangesAsync();

            var baseQuestion = new Question()
            {
                ExamId  = exam.Id,
                Content = "Question template",
                TypeId  = 1,
                Title   = "Question template",
                Value   = 1
            };

            await _context.Question.AddAsync(baseQuestion);

            await _context.SaveChangesAsync();

            var baseAnswer1 = new Answer()
            {
                Content    = "Answer template",
                Correct    = true,
                QuestionId = baseQuestion.Id
            };

            var baseAnswer2 = new Answer()
            {
                Content    = "Answer template",
                Correct    = false,
                QuestionId = baseQuestion.Id
            };

            await _context.Answer.AddRangeAsync(new List <Answer>() { baseAnswer1, baseAnswer2 });

            await _context.SaveChangesAsync();

            return(CommandResult <int> .Success(exam.Id));
        }
Exemple #2
0
        public async Task <IActionResult> Create(ExamPreCreateCommand command)
        {
            var id = await _commandBus.ExecuteAsync <int>(command);

            return(Ok(id));
        }