public Questions AddQuestion(Questions qn, Choicetable op) { _context.Questions.Add(qn); _context.SaveChanges(); op.QuestionId = qn.QuestionId; _context.Choicetable.Add(op); _context.SaveChanges(); return(qn); }
public IActionResult AddQuestion([FromBody] AddQuestionModel qnModel) { try { // map model to entity Questions qns = new Questions(); qns.CorrectAnswer = qnModel.CorrectAnswer; qns.TestId = qnModel.TestId; qns.Question = qnModel.Question; Choicetable ops = new Choicetable(); ops.ChoiceOne = qnModel.ChoiceOne; ops.ChoiceTwo = qnModel.ChoiceTwo; ops.ChoiceThree = qnModel.ChoiceThree; ops.ChoiceFour = qnModel.CorrectAnswer; //ops.QuestionId _adminService.AddQuestion(qns, ops); return(Ok()); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }