public async Task <Unit> Handle(CreateQuizEvent request, CancellationToken cancellationToken) { var exists = await _readQuizRepository.GetByIdOrNameAsync(request.Id, request.Name); if (exists.Any()) { var createQuizRejected = new CreateQuizRejectedEvent { Id = request.Id, OperationId = request.OperationId, Reason = "There's already a quiz with such Id or/and Name." }; await _busPublisher.PublishAsync(createQuizRejected); return(Unit.Value); } var entity = _mapper.Map <Quiz>(request); entity.CreatedAt = DateTime.UtcNow; _writeQuizRepository.Create(entity); await _writeQuizRepository.SaveChangesAsync(); var quizCreated = new QuizCreatedEvent { Id = request.Id, OperationId = request.OperationId }; await _busPublisher.PublishAsync(quizCreated); return(Unit.Value); }
public async Task <Unit> Handle(CreateQuizCommand request, CancellationToken cancellationToken) { var exists = await _readQuizRepository.GetByIdOrNameAsync(request.Id, request.Name); if (exists.Any()) { //TODO: Add log and/or notification. return(Unit.Value); } var entity = _mapper.Map <Quiz>(request); entity.CreatedAt = DateTime.UtcNow; _writeQuizRepository.Create(entity); await _writeQuizRepository.SaveChangesAsync(); return(Unit.Value); }