public IActionResult LoadNextQuestion(int queryNumber, int questionNumber, bool fromDelete = false) { var username = User.Identity.Name.ToString(); var user = UserOptions.GetUser(username); var query = QueryOptions.Load(user, queryNumber); query.Questions = query.Questions.OrderBy(q => q.Order).ToList(); var question = QuestionOptions.Load(query, questionNumber); question.Answers = question.Answers.OrderBy(a => a.Order).ToList(); int index = 0; for (int i = 0; i < query.Questions.Count; ++i) { if (query.Questions[i].Number == question.Number) { index = i; } } try { if (fromDelete) { QuestionOptions.SetNextActive(question, query.Questions[index].Number); } else { QuestionOptions.SetNextActive(question, query.Questions[index + 1].Number); } } catch (ArgumentOutOfRangeException ex) { } try { //var nextQuestionNumber = query.Questions.First(x => x.Number > questionNumber).Number; //var nextQuestion = QuestionOptions.Load(query, nextQuestionNumber); var nextQuestion = QuestionOptions.GetActive(query.Questions[index + 1].Number, query.Code, false); question.Answers = question.Answers.OrderBy(a => a.Order).ToList(); return(View("LoadActiveQuestion", nextQuestion)); } catch { QueryOptions.Close(query); return(RedirectToAction(nameof(UserController.Index), "User")); } }
public IActionResult SelectAnswer(int number, string code) { var question = QuestionOptions.GetActive(number, code, true); var answer = AnswerOptions.Load(question, number); AnswerOptions.Select(answer); question.IsAnswered = true; //return RedirectToAction("JoinQuery", "Client", new { code, question }); if (QueryOptions.ValidCode(code)) { return(View("ClientView", question)); } else { return(View("QueryClosed", question)); } }
public IActionResult JoinQuery(string code, Question question, int Number) { if (question != null) { question = QuestionOptions.GetActive(Number, code, question.IsAnswered); if (question == null) { question = new Question(code); } } else { question = new Question(code); } if (QueryOptions.ValidCode(code)) { return(View("ClientView", question)); } else { return(View("QueryClosed", question)); } }