public ActionResult GameList(string UId = "") { RequestHandler rh = new RequestHandler(); string userEmail = ""; if (UId != "") { userEmail = rh.VerifyUniqueID(UId); if (userEmail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "The unique id is invalid" }); } else { if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You are not logged in. Only registered users can view a list of their games" }); userEmail = GetUserEmail(WebSecurity.CurrentUserName); } //RH.getgamelist, foreach game in gamelist getusers... List<GameModel> gameList = new List<GameModel>(); List<int> gameIDs = rh.GetAllGamesForUser(userEmail); //List<int> gameIDs = gamesTask.Result; foreach (var item in gameIDs) { UIGame game = rh.GetUIGameState(userEmail, item); GameModel gm = new GameModel(); gm.GameID = item; gm.Status = game.GameState.ToString(); gm.GameName = "Game #" + item.ToString(); gm.Users.Add(GetUserName(game.CreatorEmail)); gm.UserStatus.Add("Creator"); foreach (var innerItem in game.UIUserInfo) { string Email = innerItem.UserEmail; string userName = GetUserName(Email); if (userName != "") gm.Users.Add(userName); else gm.Users.Add(Email); gm.UserStatus.Add(innerItem.State.ToString()); } gameList.Add(gm); } ViewBag.testList = gameList; return View(); }