public async Task <Unit> Handle(UpdateChoiceCommand request, CancellationToken cancellationToken) { var quiz = await _dbContext.FindQuizAsync(request.QuizId, cancellationToken); quiz.UpdateChoiceInQuestion(request.QuestionId, request.ChoiceId, request.Text, request.IsCorrect); await _dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(UpdateQuestionCommand request, CancellationToken cancellationToken) { var quiz = await dbContext.FindQuizAsync(request.QuizId, cancellationToken); Ensure(quiz, request.QuizId); quiz.UpdateQuestion(request.QuestionId, request.NewText); await dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(DeleteChoiceCommand request, CancellationToken cancellationToken) { var quiz = await _dbContext.FindQuizAsync(request.QuizId, cancellationToken); quiz.RemoveChoiceFromQuestion(request.QuestionId, request.ChoiceId); await _dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(UpdateQuizCommand request, CancellationToken cancellationToken) { var quiz = await _dbContext.FindQuizAsync(request.Id, cancellationToken); Ensure(quiz, request.Id); quiz.Name = request.Name; quiz.Description = request.Description; await _dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(DeleteQuizCommand request, CancellationToken cancellationToken) { Domain.Entities.Quiz quiz = await dbContext.FindQuizAsync(request.QuizId, cancellationToken); if (quiz == null) { throw new EntityNotFoundException($"Quiz {request.QuizId} was not found."); } dbContext.Quizes.Remove(quiz); await dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <Unit> Handle(DeleteQuestionCommand request, CancellationToken cancellationToken) { Domain.Entities.Quiz quiz = await _dbContext.FindQuizAsync(request.QuizId, cancellationToken); if (quiz == null) { throw new EntityNotFoundException("No Quiz with Question", request.QuestionId); } quiz.RemoveQuestion(request.QuestionId); await _dbContext.SaveChangesAsync(cancellationToken); return(Unit.Value); }
public async Task <AddChoiceCommandResponse> Handle(AddChoiceCommand request, CancellationToken cancellationToken) { var quiz = await _dbContext.FindQuizAsync(request.QuizId, cancellationToken); Ensure.Entity(quiz, "Quiz", request.QuizId); var addedChoiceRef = quiz.AddChoiceToQuestion(request.QuestionId, request.Text, request.IsCorrect); await _dbContext.SaveChangesAsync(cancellationToken); return(new AddChoiceCommandResponse() { NewChoiceId = addedChoiceRef.Id, Text = request.Text, IsCorrect = request.IsCorrect }); }
public async Task <AddQuestionCommandResponse> Handle(AddQuestionCommand request, CancellationToken cancellationToken) { var quiz = await dbContext.FindQuizAsync(request.QuizId, cancellationToken); Ensure(quiz, request.QuizId); var question = quiz.AddQuestion(request.Text, GetChoiceList(request.Answers)); await dbContext.SaveChangesAsync(cancellationToken); var response = new AddQuestionCommandResponse() { Id = question.Id, Answers = request.Answers }; return(response); }