public RestSharp.IRestResponse CreateQuestion(CreateQuestionDTO createQuestionDTO) { JsonObject json = new JsonObject(); json.Add("professionCode", createQuestionDTO.ProfessionCode); json.Add("imageUrl", createQuestionDTO.ImageUrl); json.Add("correctAnswerIndex", createQuestionDTO.CorrectAnswerIndex); json.Add("content", createQuestionDTO.Question); JsonArray answers = new JsonArray(); foreach (var answer in createQuestionDTO.Answers) { answers.Add(answer); } json.Add("answers", answers); RestSharp.RestRequest request = new RestSharp.RestRequest("question", RestSharp.Method.POST); request.AddJsonBody(json); RestSharp.IRestResponse response = Execute(request); return(response); }
public async Task NewQuestionCanBeCreated() { var command = new CreateQuestionDTO() { CatalogId = TestUtils.ValidQuestionsCatalog1Id, Content = "Who is your dady?", Answers = new List <CreateAnswerDTO>() { new CreateAnswerDTO() { Content = "Adam", IsCorrect = true }, new CreateAnswerDTO() { Content = "Peter", IsCorrect = false } } }; var response = await client.PostAsync(EndpointName, command); AssertExt.EnsureSuccessStatusCode(response); var createdId = response.GetContent <long>().Value; var context = factory.GetService <TestCreationDbContext>(); var actualQuestion = context.Questions.Include(x => x.Answers).FirstOrDefault(x => x.QuestionId == createdId); AssertExt.AreEquivalent(command, actualQuestion); }
public async Task <ActionResult <QuestionDTO> > Post(CreateQuestionDTO questionModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await _questionService.CreateQuestion(questionModel); if (result) { return(Ok()); } else { return(Problem( title: "Error on creating question.", detail: "Error occured on creating new question. Try again.", statusCode: 500)); } }
public async Task <IActionResult> CreateQuestionAsync([FromBody] CreateQuestionDTO createQuestionDTO) { try { var command = new CreateQuestionCommand { Description = createQuestionDTO.Description, Email = createQuestionDTO.Email, Name = createQuestionDTO.Name }; var createQuestionResult = await QuestionService.CreateQuestionAsync(command); var result = Mapper.Map <CreateQuestionResult, CreateQuestionResultDTO> (createQuestionResult); return(Ok(result)); } catch (Exception exception) { return(Exception(exception, "Failed to create question")); } }
public async Task <bool> CreateQuestion(CreateQuestionDTO questionModel) { var question = _mapper.Map <Question>(questionModel); var choices = _mapper.Map <Choice>(questionModel); question.Choices = choices; if (choices.Answers.Length > 1) { question.MultipleAnswers = true; } var result = await _questionRepository.AddAsync(question); if (result != null) { return(true); } else { return(false); } }
public async Task <ActionResult <long> > CreateQuestionWithAnswers(CreateQuestionDTO createQuestion) { var result = await Send(createQuestion.CreateCommand()); return(ActionResult(result)); }
public IRestResponse CreateQuestion(CreateQuestionDTO createQuestionDTO) { IRestResponse response = REST.RestClient.Instance.CreateQuestion(createQuestionDTO); return(response); }