Пример #1
0
        public override async Task <CreateExamCommand> HandleAsync(
            CreateExamCommand command,
            CancellationToken cancellationToken = default)
        {
            await EnsureNotExistsAsync(command, cancellationToken);

            Exam exam = null;

            await using (var dbContext = _dbContextFactory.Create(command.UserId))
            {
                exam = new Exam(
                    command.Name,
                    command.ExamDate,
                    await dbContext.ExamTypes.FirstAsync(e => e.Id == command.ExamTypeId, cancellationToken),
                    Enumeration.GetAll <ExamBookletType>().First(e => e.Id == command.ExamBookletTypeId),
                    command.IncorrectEliminationRate,
                    Enumeration.GetAll <AnswerFormFormat>().First(a => a.Id == command.AnswerFormFormat),
                    await GetLessonAsync(dbContext, command.LessonId),
                    command.ApplicableFormTypeCode,
                    command.Notes,
                    command.Shared);

                dbContext.Attach(exam.ExamBookletType);
                dbContext.Attach(exam.AnswerFormFormat);
                dbContext.Exams.Add(exam);
                await dbContext.SaveChangesAsync(cancellationToken);
            }

            await PublishEventAsync(exam, command.AnswerKeyOpticalForms, cancellationToken);

            return(await base.HandleAsync(command, cancellationToken));
        }
Пример #2
0
 private Task PublishEventAsync(
     Exam exam,
     IEnumerable <AnswerKeyOpticalForm> answerKeyOpticalForms,
     CancellationToken cancellationToken)
 {
     return(_bus.Publish(
                new ExamCreated(exam, answerKeyOpticalForms),
                cancellationToken));
 }
Пример #3
0
 private Task PublishEventAsync(
     Exam exam,
     EditExamCommand command,
     CancellationToken cancellationToken)
 {
     return(_bus.Publish(
                new ExamUpdated(exam, command.AnswerKeyOpticalForms),
                cancellationToken));
 }
Пример #4
0
 private async Task PublishEventAsync(
     Exam exam,
     EditExamCommand command,
     CancellationToken cancellationToken)
 {
     await _publishEndpoint.Publish(
         new ExamUpdated(exam, command.AnswerKeyOpticalForms),
         cancellationToken);
 }
Пример #5
0
 private async Task PublishEventAsync(
     Exam exam,
     IEnumerable <AnswerKeyOpticalForm> answerKeyOpticalForms,
     CancellationToken cancellationToken)
 {
     await _publishEndpoint.Publish(
         new ExamCreated(exam, answerKeyOpticalForms),
         cancellationToken);
 }
Пример #6
0
 private async Task UpdateExamAsync(ApplicationDbContext dbContext, EditExamCommand command, CancellationToken cancellationToken, Exam exam)
 {
     exam.Update(
         command.NewName,
         await dbContext.ExamTypes.FirstAsync(e => e.Id == command.NewExamTypeId, cancellationToken),
         command.NewIncorrectEliminationRate,
         command.NewExamDate,
         command.NewApplicableFormTypeCode,
         Enumeration.GetAll <AnswerFormFormat>().First(a => a.Id == command.NewAnswerFormFormat),
         await GetLessonAsync(dbContext, command.NewLessonId),
         Enumeration.GetAll <ExamBookletType>().First(e => e.Id == command.NewExamBookletTypeId),
         command.NewNotes);
 }