Exemplo n.º 1
0
        public Answer Create(Guid sessionEntityId, AnswerWriteDto answerDto)
        {
            var session = _repository.GetLastByFilter <Session>(c => c.Id == sessionEntityId);

            Answer newAnswer = null;

            if (session != null)
            {
                if (session.SecurityCode == answerDto.SecurityCode && session.EndDate >= DateTime.Now)
                {
                    newAnswer = new Answer
                    {
                        Id        = Guid.NewGuid(),
                        AuthorId  = Guid.NewGuid(),
                        Input     = answerDto.Answer,
                        SessionId = sessionEntityId
                    };

                    _repository.Insert(newAnswer);
                    _repository.Save();
                }
            }

            return(newAnswer);
        }
Exemplo n.º 2
0
        public IActionResult Create([FromRoute] Guid sessionEntityId, [FromBody] AnswerWriteDto answerDto)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newAnswer = _answerLogic.Create(sessionEntityId, answerDto);

            if (newAnswer == null)
            {
                return BadRequest("Invalid question.");
            }

            return CreatedAtAction(nameof(GetById), new { answerEntityId = newAnswer.Id }, answerDto);
        }