/// <summary> /// Add Answer. /// </summary> /// <returns></returns> public void AddAnswer(AnswerViewModel answerentry) { try { Answer _answer = ObjectMapper.Map <AnswerViewModel, Model.Entities.Answer>(answerentry); //Add Answer _answer.Question_Id = answerentry.Question_Id; _answer.QuizEntryId = answerentry.QuizEntryId; Answer newanswer = AnswerManager.Add(_answer); int answerId = newanswer.Id; //add Answer Questions Choices if (answerentry.Answers.Count() > 0) { foreach (var item in answerentry.Answers) { AnswerQuestionChoice _answerquestion = ObjectMapper.Map <AnswerQuestionChoiceViewModel, Model.Entities.AnswerQuestionChoice>(item); _answerquestion.AnswerId = answerId; _answerquestion.QuestionChoiceId = item.QuestionChoiceId; AnswerQuestionChoiceManager.Add(_answerquestion); } } } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing); } }
public IActionResult Post([FromBody] Answer answer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { Answer newAnswer = answerManager.Add(answer); return(Created($"answers/{newAnswer.AnswerId}", newAnswer)); } catch (Exception ex) { logger.LogError($"Failed to insert answer: {ex}"); return(BadRequest(config["Error:Default"])); } }