protected void Page_Load(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated == true) { Person ObjPerson = new Person(int.Parse(this.Page.User.Identity.Name)); if (ObjPerson.Role == "JobSeeker") { LnkBtnAnswer.Visible = false; } if (ObjPerson.Role == "Recruiter") { LnkBtnAnswer.Visible = true; } } else { LnkBtnAnswer.Visible = false; } //throw new Exception(QuestionID.ToString()); Question ObjQuestion = new Question(QuestionID); LblQuestion.Text = ObjQuestion.QuestionName; if (Question_Answer.GetQuestion_AnswerRecords("QuestionId=" + QuestionID).Rows.Count > 0) { LblAnswer.Text = Question_Answer.GetQuestion_AnswerRecords("QuestionId=" + QuestionID).Rows[0]["Answer"].ToString(); } }
protected void BtnAddAnswer_Click(object sender, EventArgs e) { if (this.Page.IsValid == true) { Question_Answer.AddQuestion_Answer(QuestionID, TxtAnswer.Text); DivAddAnswerModal.Visible = false; Page_Load(null, null); } }
protected void LnkBtnAnswer_Click(object sender, EventArgs e) { DivAddAnswerModal.Visible = true; if (Question_Answer.GetQuestion_AnswerRecords("QuestionId=" + QuestionID).Rows.Count > 0) { TxtAnswer.Text = Question_Answer.GetQuestion_AnswerRecords("QuestionId=" + QuestionID).Rows[0]["Answer"].ToString(); } TxtAnswer.Focus(); this.Page.Form.DefaultButton = BtnAddAnswer.UniqueID; }
public ActionResult Take(Poll selectedPoll) { if (selectedPoll != null) { Answers_Header header = new Answers_Header(); header.IpAddress = Request.UserHostAddress; using (DataLayer_SimplePoll dl = new DataLayer_SimplePoll()) { long?UserId = dl.User_Save(User.Identity.Name); if (UserId.HasValue && UserId.Value != 0) { header.UserId = UserId.Value; } int?UserAgentId = dl.UserAgent_Save(Request.UserAgent.ToString()); if (UserAgentId.HasValue && UserAgentId.Value != 0) { header.UserAgentId = UserAgentId.Value; } Question_Answer selectedAnswer = selectedPoll.Question.Answers.FirstOrDefault(ans => Guid.Equals(ans.AnswerId, selectedPoll.Question.SelectedAnswer)); if (selectedAnswer != null) { Question_Answer_Response response = new Question_Answer_Response(); response.AnswerId = selectedAnswer.AnswerId; response.QuestionId = selectedAnswer.QuestionId; header.Responces.Add(response); } dl.Poll_Responses_Save(header); } } return(RedirectToAction("Index")); }
public ActionResult CreateQuestionsView([Bind(Include = "Question, Answer1, Answer2, Answer3, Answer4, CorrectAnswer, Publish")] Question_Answer qa) { if (ModelState.IsValid) { //checks if all the fields have values in them if (qa.Question != null && qa.Answer1 != null && qa.Answer3 != null && qa.Answer4 != null && qa.CorrectAnswer != null) { //check to see that one of the possible answers matches the correct answer if (qa.Answer1 == qa.CorrectAnswer || qa.Answer2 == qa.CorrectAnswer || qa.Answer3 == qa.CorrectAnswer || qa.Answer4 == qa.CorrectAnswer) { qa.TestID = Session["TestID"].ToString(); int count = 1; List <Question_Answer> list = db.Question_Answer.ToList(); //piece of code that finds the last known ID and increments it by 1 for (int i = 0; i < list.Count; i++) { Question_Answer item = list[i]; if (count != Int32.Parse(item.QuestionID.Substring(2, 3))) { if (count < 10) { qa.QuestionID = "Q000" + count; } else if (count < 100 && count > 10) { qa.QuestionID = "Q00" + count; } else { qa.QuestionID = "Q0" + count; } } else { count++; if (count > list.Count) { if (count < 10) { qa.QuestionID = "Q000" + count; } else if (count < 100 && count >= 10) { qa.QuestionID = "Q00" + count; } else { qa.QuestionID = "Q0" + count; } } } } //loads data into table db.Question_Answer.Add(qa); db.SaveChanges(); return(RedirectToAction("CreateQuestionsView")); } else { ViewBag.Error = "Correct Answer does not match any possible answers"; return(View()); } } { ViewBag.Error = "Correct Answer does not match any possible answers"; return(View()); } } return(View(qa)); }