예제 #1
0
        public ActionResult PutAnswerById(AnswerInputModel answerModel)
        {
            Mapper           mapper    = new Mapper();
            AnswerDTO        answerdto = mapper.ConvertAnswerInputModelToAnswerDTO(answerModel);
            AuthorDataAccess answers   = new AuthorDataAccess();
            var answer = answers.GetAnswerById(answerModel.ID);

            if (answer == null)
            {
                return(BadRequest("Ответа не существует"));
            }
            var question = answers.GetQuestionById(answerModel.QuestionID);

            if (question == null)
            {
                return(BadRequest("Вопроса не существует"));
            }
            if (string.IsNullOrWhiteSpace(answerModel.Value))
            {
                return(BadRequest("Введите ответ"));
            }
            if (answerModel.Correct == null)
            {
                return(BadRequest("Введите корректный ответ или нет"));
            }
            answers.UpdateAnswerById(answerdto);
            return(Ok("Успешно изменено!"));
        }
예제 #2
0
        public ActionResult <int> DeleteAnswerById(int answerId)
        {
            AuthorDataAccess answers = new AuthorDataAccess();
            var answer = answers.GetAnswerById(answerId);

            if (answer == null)
            {
                return(BadRequest("Ответа не существует"));
            }
            answers.DeleteAnswerById(answerId);
            return(Ok(answerId));
        }