public ActionResult Index(GuessAndHighScore model) { if (ModelState.IsValid && !this.Session.IsNewSession) { model.Guess.Result = Guess.HighOrLow((int)this.Session["Answer"], model.Guess.UserGuess); (this.Session["GuessList"] as List <int>).Add(model.Guess.UserGuess); model.Guess.GuessCount = (this.Session["GuessList"] as List <int>).Count(); HttpCookie requestCookie = Request.Cookies["GuessingGame"]; try { model.HighScore = CookieHelper.ReadCookie <HighScore>(requestCookie, "HighScore"); if (model.HighScore == null) { throw (new Exception("HighScore was null!")); } } catch (Exception e) { model.HighScore = new HighScore(); } //highscore check if (model.Guess.Result == GuessResult.CORRECT) { model.HighScore.InsertScore((this.Session["GuessList"] as List <int>).Count()); HttpCookie responseCookie = Response.Cookies["GuessingGame"]; CookieHelper.WriteCookie(responseCookie, "HighScore", model.HighScore, DateTime.Now.AddYears(1)); //return RedirectToAction("Index"); } return(View(model)); } else { return(RedirectToAction("Index")); } }