public IActionResult Create([FromBody] AnswerSubmission questionOption) { if (questionOption == null) { return(BadRequest(new { message = "Bad request" })); } try { _answerSubmissionService.Create(questionOption); return(Ok()); } catch (Exception ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public IActionResult Save([FromBody] List <QuestionsDto> ListQuestionsDto) { if (ListQuestionsDto == null) { return(BadRequest()); } var anonymousUser = _anonymousUserService.Create(new AnonymousUser() { SurveyID = ListQuestionsDto[0].SurveyId, CreatedOn = DateTime.Now }); foreach (var questionsubmitted in ListQuestionsDto) { foreach (var item in questionsubmitted.Qoptions) { var answersubmitted = _mapper.Map <AnswerSubmission>(item); answersubmitted.AnonymouseUserID = anonymousUser.Id; _answerSubmissionService.Create(answersubmitted); } } return(Ok()); }