public void UpdateStoppedSessionGame(UserGame game)
        {
            ActiveGames = Session[MvcApplication.ActiveGamesKey] as UserActiveGames;
            var g = ActiveGames.findGame(game.UserGameSessionID);

            if (g == null)
            {
                ActiveGames.AddGame(game);
            }
            else
            {
                g.Cells = game.Cells;
            }
        }
        // http://stackoverflow.com/questions/18954830/mvc4-how-to-hook-the-onsessionstart-event

        protected void Session_Start(object sender, EventArgs e)
        {
            // event is raised each time a new session is created
            Session[ActiveGamesKey] = new UserActiveGames();
        }
        public ActionResult Create(
            UserGame userGame)


        //[Bind(Include = "UserGameID,UserID,Name,Height,Width,Cells")] UserGame userGame)
        {
            //if (Session.Keys.Count == 0)
            //{
            //    ActiveUserGameList = new List<UserGame>();
            //}

            //UserGame userGame = viewmodel.UserGame;
            //ActiveUserGameList.Add(userGame);

            // TODO:
            // retrieve x and y coords from the Form Request
            // to use as parameters for InsertTemplate()

            int x = Int32.Parse(Request.Form["Xcoord"]);
            int y = Int32.Parse(Request.Form["YCoord"]);

            // grab the template cells from TempData
            UserTemplate template = TempData["template"] as UserTemplate;

            // add the template the game so we can access it in the validators
            userGame.templateHeight = template.Height;
            userGame.templateWidth  = template.Width;

            //userGame.Template = template;

            // intialise the Game cells
            userGame.initialiseCells();


            // TODO:
            // call InsertTemplate() (either in Game or here)

            userGame.InsertTemplate(template, x, y);



            if (ModelState.IsValid)
            {
                // add the Game to the session
                ActiveGames = Session[MvcApplication.ActiveGamesKey] as UserActiveGames;
                ActiveGames.AddGame(userGame);

                // redirect to a list of active Games (session)
                return(RedirectToAction("ListActiveGames"));


                // pass the Game to NewGameDetails() Action
                // https://msdn.microsoft.com/en-us/library/dd394711(v=vs.100).aspx
                //TempData["game"] = userGame;
                //return RedirectToAction("NewGameDetails");
                //return RedirectToAction("Index");
            }

            ViewBag.UserID = new SelectList(db.Users, "UserID", "Email", userGame.UserID);
            return(View(userGame));
        }