public ActionResult AddRightAnswerToTest(Guid[] allAnswersId, Guid questionId, Guid idTest, Guid subjectId, Guid[] rightAnswersId) { if (rightAnswersId != null) { AnswerDTO[] ansversSave = TempData["ansvers"] as AnswerDTO[]; QuestionDTO question = TempData["question"] as QuestionDTO; questionService.AddNewQuestion(question); TestDTO testDTO = testService.GetTestById(idTest); //testDTO.CountQuestion += 1; testService.UpdateTest(testDTO); questionService.AddNewCOnnectionTestQuestion(idTest, question.Id); for (int i = 0; i < ansversSave.Length; i++) { answerService.AddNewAnswer(ansversSave[i]); } int count = 0; foreach (var ansv in allAnswersId) { if (rightAnswersId != null) { count = 0; foreach (Guid id in rightAnswersId) { count++; if (ansv == id) { answerService.AddNewConnectionQuestionAnswer(questionId, ansv, true); break; } if (count == rightAnswersId.Length) { answerService.AddNewConnectionQuestionAnswer(questionId, ansv, false); } } } else { answerService.AddNewConnectionQuestionAnswer(questionId, ansv, false); } } return(RedirectToAction("ViewQuestion", new { subjectId = subjectId, id = idTest })); } AnswerDTO[] ansvers = new AnswerDTO[allAnswersId.Length]; for (int i = 0; i < allAnswersId.Length; i++) { AnswerDTO answerDTO = new AnswerDTO(); answerDTO = answerService.GetAnswerById(allAnswersId[i]); ansvers[i] = answerDTO; } Logger.Log.Info("User " + User.Identity.GetUserId() + "add new question and answers to test " + idTest); TempData["ansversBack"] = ansvers; return(RedirectToAction("AddRightAnswerToTest", new { questionId = questionId, ansversc = allAnswersId.Length, idTest = idTest, subjectId = subjectId })); }
public IHttpActionResult Post([FromBody] AnswerDTO answerDto) { if (answerDto == null) { return(BadRequest(message: "Body was empty!")); } var ret = _answerService.AddNewAnswer(answerDTO: answerDto); if (ret == null) { return(BadRequest(message: _answerService.LastErrorMessage)); } return(CreatedAtRoute(routeName: "DefaultApi", routeValues: new { id = ret.Id }, content: ret)); }
public ActionResult AddAnswer(AnswerDTO answerDTO, bool?isRight, Guid subjectId, Guid idTest, Guid questionId) { if (ModelState.IsValid) { answerDTO.Id = Guid.NewGuid(); answerService.AddNewAnswer(answerDTO); if (isRight != null) { answerService.AddNewConnectionQuestionAnswer(questionId, answerDTO.Id, true); } else { answerService.AddNewConnectionQuestionAnswer(questionId, answerDTO.Id, false); } Logger.Log.Info("User " + User.Identity.GetUserId() + "add new answer to test " + idTest); } return(RedirectToAction("ViewQuestion", "TestQuestion", new { subjectId = subjectId, id = idTest })); }