Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 public ActionResult ViewStatus(int gameId = -1, string UId = "")
 {
     string userMail = "";
     UIGame game = null;
     RequestHandler rh = new RequestHandler();
     if (UId != "")
     {
         userMail = rh.VerifyUniqueID(UId);
         if (userMail == null) return RedirectToAction("ErrorPage", new { ErrorMessage = "The unique id is invalid" });
         //if (gameId != gi.GameId) return RedirectToAction("ErrorPage", new { ErrorMessage = "There was an error while processing the request. The requested game does not match with the given UID." });
         //userMail = gi.ActUserEmail;
         game = rh.GetUIGameState(userMail, gameId);
     }
     else if (!WebSecurity.IsAuthenticated) return RedirectToAction("ErrorPage", new { ErrorMessage = "You have to be logged in or provide the UId to view the requested page" });
     else
     {
         userMail = GetUserEmail(WebSecurity.CurrentUserName);
         game = rh.GetUIGameState(userMail, gameId);
     }
     GameModel gm = new GameModel();
     gm.GameName = "Game #" + gameId.ToString();
     gm.GameID = gameId;
     gm.Status = game.GameState.ToString();
     ViewBag.CreatorName = GetUserName(game.CreatorEmail);
     foreach (var item in game.UIUserInfo)
     {
         string userName = GetUserName(item.UserEmail);
         if (userName != "") gm.Users.Add(userName);
         else gm.Users.Add(item.UserEmail);
         gm.UserStatus.Add(item.State.ToString());
         if (userMail == item.UserEmail) ViewBag.PlayerStatus = item.State.ToString();
     }
     bool showstartLink = true;
     if (game.CreatorEmail == userMail && rh.CanStart(gameId)) showstartLink = true;
     else showstartLink = false;
     ViewBag.UId = UId;
     ViewBag.ShowStartLink = showstartLink;
     ViewBag.GameId = gameId.ToString();
     ViewBag.Game = gm;
     return View();
 }