public ActionResult Detail(Guid id, AnswerViewModels model) { Answer ans = new Answer() { Id = Guid.NewGuid(), Content = model.Content, CreateDate = DateTime.Now, CreateBy = User.Identity.GetUserName(), QuestionID = id }; var answerquestion = _answerService.Create(ans); return(RedirectToAction("Detail")); }
public ActionResult Create(int?TestID) { if (TestID == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Test test = db.Tests.Find(TestID); if (test == null) { return(HttpNotFound()); } if (test.Status == "Prepared") { TempData["msg"] = "Nie można wypełnić testu, który jest przygotowywany!"; TempData["option"] = "warning"; return(RedirectToAction("Index", "Tests")); } CreateResultViewModels result = new CreateResultViewModels(); result.TestID = test.Id_testu; result.TestTitle = test.Title; result.TestSubject = test.Subject; result.TestCreator = test.Created_by; result.TestData = test.Created_at; result.TestQuestions = test.Questions.ToList(); ViewBag.QuestionsCount = result.TestQuestions.Count; //utworzenie listy obiektów na odpowiedzi do testu var answersList = new List <AnswerViewModels>(); for (int i = 0; i < result.TestQuestions.Count; i++) { var answer = new AnswerViewModels(); answer.Id_question = result.TestQuestions[i].Id_question; answer.Content = " "; answersList.Add(answer); } result.AnswersViewModels = answersList; return(View(result)); }