public IActionResult Answer(int id) { string un = Request.Cookies["username"]; if (string.IsNullOrWhiteSpace(un)) { return(View("Error", "Invalid username!")); } ARQuizz.Session s = ARQuizz.Session.GetCurrentSession(un); if (s == null) { return(View("Error", "Session timed out!")); } s.Answer(id); if (s.IsLastQuestion()) { return(Redirect("/Home/GetQuizzResult/-1")); } return(Redirect("/Home/GetNextQuestion?UserName=" + un)); }
public async Task <IActionResult> Answer(int id) { return(await Task.Run <IActionResult>(() => { string un = Request.Cookies["username"]; if (string.IsNullOrWhiteSpace(un)) { return View("Error", "Invalid username!"); } ARQuizz.Session s = ARQuizz.Session.GetCurrentSession(un); if (s == null) { return Redirect("/Quizz/ShowYourResult/" + un); } Task.WaitAll(s.Answer(id)); if (s.IsLastQuestion()) { return Redirect("/Quizz/Result/-1"); } if (id == -1) { return Redirect("/Quizz/GetQuizzResult?UserName="******"/Quizz/Question/Next?UserName=" + un); })); }
public async Task <IActionResult> GetCurrentSession() { return(await Task.Run(() => { string un = Request.Cookies["username"]; ARQuizz.Session s = ARQuizz.Session.GetCurrentSession(un); if (s != null && s.TimeLeft <= 0) { Task.WaitAll(s.Finish()); } JsonResult r = Json(JsonConvert.SerializeObject(s)); return r; })); }
public async Task <IActionResult> QuestionNext(string UserName, int Type) { return(await Task.Run <IActionResult>(() => { ARQuizz.Question q = null; ARQuizz.Session s = null; if (string.IsNullOrWhiteSpace(Request.Cookies["username"])) { Response.Cookies.Append("username", UserName); } s = ARQuizz.Session.GetCurrentSession(Request.Cookies["username"]); if (s == null) { s = new ARQuizz.Session(UserName, Type); } if (!s.Check()) { q = s.GetNextQuestion(); } if (s == null) { return View("Error", "Session time out!"); } if (q == null) { Task.WaitAll(s.Finish()); return Redirect("/Quizz/Result/-1"); } return View("Question", q); })); }
public async Task <IActionResult> GetQizzResult(int id) { return(await Task.Run <IActionResult>(() => { List <ARQuizz.Session> list = ARQuizz.Session.List(); list = ARQuizz.Session.List(); if (id == -1) { string un = Request.Cookies["username"]; if (string.IsNullOrEmpty(un)) { return View("Error", "User does not exist"); } ARQuizz.Session s = list.Where(x => x.UserName == un).OrderBy(t => t.End).Take(1).FirstOrDefault(); return View("Session", list.Where(x => x.UserName == un).OrderBy(t => t.End).Take(1).ToList()); } // Ucitati rezultat iz baze. Ukoliko je id == -1 onda ucitati poslednji rezultat za username iz cookija return View("Session", list); })); }