public IActionResult CloseQuery(int queryID) { var username = User.Identity.Name.ToString(); var user = UserOptions.GetUser(username); var query = QueryOptions.Load(user, queryID); query.Questions = query.Questions.OrderBy(q => q.Order).ToList(); QueryOptions.Close(query); return(RedirectToAction(nameof(UserController.Index), "User")); }
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")); } }