예제 #1
0
        public async Task <IActionResult> EditQuestion(int id, QuestionForAddDto QuestionForAddDto)
        {
            var questionFromRepo = await _repo.GetQuestion(id);

            var question = new QuestionForUpdateDto
            {
                Content = QuestionForAddDto.Content,
            };
            var q = _mapper.Map(question, questionFromRepo);
            await _repo.SaveAll();

            foreach (var answer in QuestionForAddDto.Answer)
            {
                var ans = new AnswerForUpdateDto
                {
                    Content = answer.Content,

                    AnswerTrue = answer.AnswerTrue
                };
                var answerFromRepo = await _repo.GetAnswer(answer.Id);

                var a = _mapper.Map(ans, answerFromRepo);
                await _repo.SaveAll();
            }

            return(CreatedAtRoute("GetQuestion", new { id = questionFromRepo.Id }, questionFromRepo));
        }
예제 #2
0
        public async Task <IActionResult> AddItem(QuestionForAddDto QuestionForAddDto)
        {
            var question = new Question
            {
                Content = QuestionForAddDto.Content,
                Url     = QuestionForAddDto.Url,
                TypeId  = QuestionForAddDto.TypeId
            };



            _repo.Add(question);
            if (await _repo.SaveAll())
            {
                var questionToReturn = _mapper.Map <Question>(question);
                foreach (var answer in QuestionForAddDto.Answer)
                {
                    var ans = new Answer
                    {
                        Content    = answer.Content,
                        QuestionId = question.Id,
                        AnswerTrue = answer.AnswerTrue
                    };
                    _repo.Add(ans);
                    await _repo.SaveAll();
                }
                return(CreatedAtRoute("GetQuestion", new { id = question.Id }, questionToReturn));
            }

            return(BadRequest("Could not add the photo"));
        }