public JsonResult Post([FromBody] List <AnswerQuestion> answerItems) { answer.AnswerQuestions = answerItems; if (answer.IsRequiredQuestionsFilled()) { answer.AddAnswer(); return(Json(new { status = "OK" })); } else { return(Json(new { status = "ERROR", message = "Обязательные пункты опроса не заполнены." })); } }
public IActionResult AddAnswer(string answer, string goodanswer, int idSurvey) { ViewBag.NbreVisitUnique = GetVisitIP(); ViewBag.NbrePagesVues = GetPageVues(); UserConnect(ViewBag); if (!ViewBag.Logged) { return(RedirectToRoute(new { controller = "Membres", action = "Login" })); } if ((ViewBag.Statut != "Administrateur") && (ViewBag.Statut != "Coeur")) { return(RedirectToRoute(new { controller = "Membres", action = "Login" })); } Answer a = new Answer { IdSurvey = idSurvey, Label = answer }; if (goodanswer == "good") { a.GoodAnswer = true; } else { a.GoodAnswer = false; } List <Answer> answers = a.AddAnswer(); Survey s = new Survey { Id = idSurvey }; s = s.GetSurvey(); s.Answers = answers; return(View("AddSurvey", s)); }
//Save Value For NonScore Section private int GetValueNonScore() { try { int answerOID = 0; Student student = (Student)(Session["currentStd"]); int aoid = Convert.ToInt32(Session["aoid"].ToString()); //Get Assessment By OID ass = ass.GetAssessmentByOID_QuestionSheet(aoid); //Assign Value to Answer ans = ans.GetAnswerBySOIDAndAOID(student.StudentOID, aoid); if (ans == null) { ans = new Answer(); ans.CreatedDate = DateTime.Now; ans.AssessmentOID = ass.AssessmentOID; ans.CreatedBy = 1; ans.NumberOfPrinted = 0; ans.BannerID = student.StudentID; ans.StudentOID = student.StudentOID;//Get Currently Login Student OID ansDetailList.Clear(); foreach (Section s in ass.SectionList) { if (s.SectionName == "NoScore") { //to do for section //Each Question foreach (Question q in s.QuestionList) { QResponselistPerOID.Clear(); QResponselistPerOID = qresponse.GetQuestionRespByQOID(q.QuestionOID); ansDetail = new AnswerDetail(); ansDetail.CreatedBy = 1; ansDetail.SectionOID = s.SectionOID; ansDetail.QuestionOID = q.QuestionOID; response = null; foreach (QuestionResponse qr in QResponselistPerOID) { fieldName1 = Convert.ToString("A" + q.QuestionOID + qr.QuestionResponseOID); fieldName1 = Request.Form[fieldName1]; if (fieldName1 != null) { response = qr.Response; } //else //{ // response = "No Answer"; //} } ansDetail.Response = response; ansDetailList.Add(ansDetail); } } } //Assign Answer Details List to ans.AnswerDetailList = ansDetailList; //Save if (ans.AnswerOID > 0) { ans.addAnswerDetails(ans.AnswerOID); ansDetailList.Clear(); } else { answerOID = ans.AddAnswer(); ansDetailList.Clear(); } } return answerOID; } catch { return 0; } }