public ActionResult PutAnswer(int testId, int questionId, int answerId,
                                      QuizAnswer quizAnswer)
        {
            var result = _quizService.EditAnswer(answerId, quizAnswer);

            if (result == false)
            {
                return(Forbid());
            }
            return(Ok());
        }
        public ActionResult PostAnswer(int testId, int questionId, QuizAnswer quizAnswer)
        {
            var answerId = _quizService.CreateAnswer(questionId, quizAnswer);

            if (answerId == 0)
            {
                return(Forbid());
            }
            return(Ok(new QuizAnswer {
                Id = answerId, QuestionId = questionId
            }));
        }
Example #3
0
        public bool EditAnswer(int answerId, QuizAnswer answer)
        {
            var element = _context.QuizAnswers.FirstOrDefault(a => a.Id == answerId);

            if (element == null)
            {
                return(false);
            }
            element.Content = answer.Content;
            _context.QuizAnswers.Update(element);
            _context.SaveChanges();
            return(true);
        }
Example #4
0
        public int CreateAnswer(int questionId, QuizAnswer answer, int authorId = 1)
        {
            var question = _context.QuizQuestions.FirstOrDefault(q => q.Id == questionId);

            if (question == null)
            {
                return(0);
            }
            var newAnswer = new QuizAnswer
            {
                Content    = answer.Content,
                QuestionId = questionId,
                AuthorId   = authorId
            };

            _context.QuizAnswers.Add(newAnswer);
            _context.SaveChanges();
            foreach (var file in answer.Files)
            {
                _fileDataService.CreateForQuizAnswer(file, newAnswer.Id);
            }
            return(newAnswer.Id);
        }