public async Task <Question> AddQuestion(AddQuestionCommand command) { var answers = command.Answers.Select(x => new Answer(x.Text, x.IsCorrect)).ToList(); var question = new Question(command.Text, answers); return(await _questionRepository.AddQuestion(question)); }
public async Task <IActionResult> CreateQuestion(int quizId, [FromBody] AddQuestionCommand addQuestionCommand) { Expect(addQuestionCommand, c => c != null); Expect(addQuestionCommand, c => c.QuizId == quizId); AddQuestionCommandResponse response = await Mediator.Send(addQuestionCommand); return(Created(GetLocationUrl(response.Id), response)); }
public async Task <IActionResult> AskQuestion(AddQuestionCommand command) { if (!ModelState.IsValid) { return(PartialView("_AskQuestion", command)); } await _mediator.Send(command); return(PartialView("_AskQuestion")); }
public AddTestVM() { AddQuestionCommand = new AddQuestionCommand(this); deleteanswerComand = new DeleteAnswerComand(this); addanswerComand = new AddAsnwerComand(this); addQuestionWindowComand = new AddQuestionWindowCommand(this); questions = new ObservableCollection <QuestionDTO>(); Answers = new ObservableCollection <AnswerOptionDTO>(); NewTest = new TestDTO(); }
public async Task <Result <QuestionResponse> > Add(AddQuestionCommand command) { var validationResult = Validate(await _addQuestionCommandValidator.Validate(command)); if (!validationResult.Success) { return(validationResult); } var question = command.ToQuestion(); await _repository.Add(question); return(new Result <QuestionResponse>(new QuestionResponse())); }
public async Task Should_Add_Question() { var command = new AddQuestionCommand() { Name = "TESTE", Answers = new List <QuestionAnswerDto>() { new QuestionAnswerDto() { Id = Guid.NewGuid(), Name = "TESTE", Correct = true } } }; var result = await _service.Add(command); result.Success.Should().BeTrue(); }
public async Task Should_Not_Add_Question() { var command = new AddQuestionCommand() { Name = "TESTE", Answers = new List <QuestionAnswerDto>() { new QuestionAnswerDto() { Id = Guid.NewGuid(), Name = "BMW", Correct = false } } }; var result = await _service.Add(command); result.Success.Should().BeFalse(); result.Message.Should().Be(QuestionValidationMessages.NO_CORRECT_ANSWER); }
public async Task <ValidationResult> Validate(AddQuestionCommand command) { var result = new ValidationResult(); if (string.IsNullOrEmpty(command.Name)) { result.AddMessage(QuestionValidationMessages.NAME); } else if (await _repository.VerifyExistence(command.Name, null)) { result.AddMessage(QuestionValidationMessages.NAME_EXISTS); } if (!command.Answers.Any()) { result.AddMessage(QuestionValidationMessages.NO_ANSWERS); } if (!command.Answers.Any(answer => answer.Correct)) { result.AddMessage(QuestionValidationMessages.NO_CORRECT_ANSWER); } return(result); }
public void ShouldStoreQuestionWhenNewQuestionIsAdded() { // Given var questionId = Guid.NewGuid(); var command = new AddQuestionCommand { QuestionId = questionId, Text = "What is the capital of Belgium?", Tags = new List <string> { "Geography", "Cities" }, }; // When Writer.Process(command); // Then var query = new FindQuestionsByIdsQuery() .AddQuestionIds(questionId); var result = Reader.Process(query); Assert.That(result.Questions.Single(p => p.Id == questionId), Is.Not.Null); result.Dump(); }
public async Task AddQuestion([FromBody] AddQuestionCommand command, CancellationToken cancellationToken) { await _mediator.Send(command, cancellationToken); }
public async Task <Result <QuestionResponse> > Post([FromBody] AddQuestionCommand command) => await _service.Add(command);
public async Task <IActionResult> Post([FromBody] AddQuestionCommand command) { var result = await _addQuestionCommandHandler.AddQuestion(command); return(CreatedAtAction(nameof(Get), new { id = result.Id }, result)); }