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)); }
private Task PublishEventAsync( Exam exam, IEnumerable <AnswerKeyOpticalForm> answerKeyOpticalForms, CancellationToken cancellationToken) { return(_bus.Publish( new ExamCreated(exam, answerKeyOpticalForms), cancellationToken)); }
private Task PublishEventAsync( Exam exam, EditExamCommand command, CancellationToken cancellationToken) { return(_bus.Publish( new ExamUpdated(exam, command.AnswerKeyOpticalForms), cancellationToken)); }
private async Task PublishEventAsync( Exam exam, EditExamCommand command, CancellationToken cancellationToken) { await _publishEndpoint.Publish( new ExamUpdated(exam, command.AnswerKeyOpticalForms), cancellationToken); }
private async Task PublishEventAsync( Exam exam, IEnumerable <AnswerKeyOpticalForm> answerKeyOpticalForms, CancellationToken cancellationToken) { await _publishEndpoint.Publish( new ExamCreated(exam, answerKeyOpticalForms), cancellationToken); }
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); }