Exemple #1
0
 public async void CreateNewAnswer_ReturnsBadRequest(CreateAnswerCommand a, CreateAnswerCommand b,
                                                     CreateAnswerCommand c)
 {
     Assert.True(await IsBadRequest(a));
     Assert.True(await IsBadRequest(b));
     Assert.True(await IsBadRequest(c));
 }
Exemple #2
0
        private async Task <bool> IsSuccessStatusCode(CreateAnswerCommand command)
        {
            var content = Utilities.GetRequestContent(command);

            var response = await _client.PostAsync($"/api/requests/{command.RequestId}/answers", content);

            return(response.StatusCode.ToString() == "NoContent");
        }
Exemple #3
0
        public async Task CreateNewAnswer_ReturnsSuccessStatusCode()
        {
            //Arrange
            var command = new CreateAnswerCommand
            {
                TextTranslated = "Den er nu fikset",
                RequestId      = 1,
                UserId         = Guid.Parse("8e3f52d0-ee7e-4353-8941-ab1b75bbdf76")
            };

            Assert.True(await IsSuccessStatusCode(command));
        }
        public async Task <IActionResult> Create(Guid questionId, string answer)
        {
            CreateAnswerCommand command = new CreateAnswerCommand()
            {
                Description = answer,
                QuestionId  = questionId
            };

            await AnswerService.CreateAnswerAsync(command);

            return(RedirectToAction("Question", "Question", new { id = questionId }));
        }
Exemple #5
0
        public async Task <int> InsertAnswerAsync(CreateAnswerCommand command)
        {
            try
            {
                var result = await client.PostAsync($"{baseUrl}/api/answer/", RequestHelper.GetStringContentFromObject(command));

                return(Convert.ToInt32(result.Content.ReadAsStringAsync().Result));
            }
            catch (Exception e)
            {
                throw e.InnerException;
            }
        }
        public async Task <ActionResult <int> > Post([FromBody] CreateAnswerCommand command)
        {
            var entity = new Answer
            {
                Text       = command.Text,
                Weight     = command.Weight,
                QuestionId = command.QuestionId,
            };

            _context.Answer.Add(entity);

            await _context.SaveChangesAsync();

            return(Ok(entity.Id));
        }
        private CommandResponse ExecuteCreateAnswer(CreateAnswerCommand command)
        {
            var existingQuestion = Questions.FirstOrDefault(q => q.Id == command.QuestionId);

            if (existingQuestion == null)
            {
                return(CommandResponse.Failure($"Question {command.QuestionId} doesn't exist."));
            }

            var answer = new Answer
            {
                Author    = command.IssuedBy,
                Id        = Guid.NewGuid(),
                Timestamp = DateTime.Now,
                Text      = command.Text
            };

            existingQuestion.Answers.Add(answer);

            return(CommandResponse.Success(answer));
        }
        public async Task <IActionResult> CreateAnswerAsync([FromBody] CreateAnswerDTO createAnswerDTO)
        {
            try
            {
                CreateAnswerCommand command = new CreateAnswerCommand()
                {
                    Description = createAnswerDTO.Description,
                    QuestionId  = createAnswerDTO.QuestionId
                };

                var createAnswerResult = await AnswerService.CreateAnswerAsync(command);

                var result = Mapper.Map <CreateAnswerResult, CreateAnswerResultDTO> (createAnswerResult);

                return(Ok(result));
            }
            catch (Exception exception)
            {
                return(Exception(exception, "Failed to create answer"));
            }
        }
Exemple #9
0
        public async Task <IActionResult> CreateAnswerAsync([FromBody] CreateAnswerRequest model,
                                                            CancellationToken token)
        {
            var userId = _userManager.GetLongUserId(User);

            try
            {
                var command = new CreateAnswerCommand(model.QuestionId, model.Text, userId);
                await _commandBus.DispatchAsync(command, token);

                return(Ok());
            }
            catch (QuotaExceededException)
            {
                ModelState.AddModelError(nameof(model.Text), _localizer["You exceed your quota of answers"]);
                return(BadRequest(ModelState));
            }
            catch (ArgumentException)
            {
                ModelState.AddModelError(nameof(model.Text), _localizer["QuestionNotExists"]);
                return(BadRequest(ModelState));
            }
        }
Exemple #10
0
        public async Task <IActionResult> Create(CreateAnswerCommand command)
        {
            var result = await Mediator.Send(command);

            return(GetResponse(result));
        }
Exemple #11
0
        public async Task <ActionResult <int> > Create([FromBody] CreateAnswerCommand command)
        {
            var answerId = await _mediator.Send(command);

            return(Ok(answerId));
        }
 public async Task <IActionResult> CreatePollAnswer(CreateAnswerCommand request)
 {
     return(Ok(await _mediator.Send(request)));
 }
        public async Task <IActionResult> CreateAnswer([FromBody] CreateAnswerCommand command)
        {
            await Mediator.Send(command).ConfigureAwait(false);

            return(NoContent());
        }