예제 #1
0
        public async Task <IActionResult> ChangeStatus(string id, string adminToken, int newStatus)
        {
            var game = await _repo.GetGame(id);

            // Score the game if we are closing it
            if (newStatus == 2)
            {
                ScoreGame(game);
            }

            game.Status = newStatus;

            await _repo.UpdateGame(game);

            return(RedirectToAction("Index", "Admin", new { id, adminToken }));
        }
예제 #2
0
        public async Task <IActionResult> Register(PlayerRegisteringViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("PlayerRegistering", model));
            }

            var game = await _repo.GetGame(model.GameID);

            var player = game.Players.SingleOrDefault(p => p.ID == model.PlayerID);

            if (player == null)
            {
                player = new Player {
                    ID = _repo.GetNewId()
                };
                game.Players.Add(player);
            }

            player.Name   = model.Name;
            player.Symbol = model.Symbol;
            player.Color  = model.ColorCode;
            player.Fact   = model.Fact;
            player.FactID = _repo.GetNewId();

            await _repo.UpdateGame(game);

            var hasCookie = Request.Cookies.ContainsKey("FactGameGame" + model.GameID);

            if (!hasCookie)
            {
                var cookieOptions = new CookieOptions
                {
                    HttpOnly = true,
                    Expires  = DateTime.Now.AddYears(1),
                    Secure   = Request.IsHttps
                };

                Response.Cookies.Append("FactGameGame" + model.GameID, player.ID, cookieOptions);
            }

            TempData["fg-player-registered"] = true;

            return(RedirectToAction("Index", "Player", new { id = model.GameID }));
        }
예제 #3
0
        public async Task <IActionResult> CreateGame(CreateGameViewModel model)
        {
            var game = new Game
            {
                ID         = _repo.GetNewId(),
                Name       = model.Name,
                AdminToken = _repo.GetNewId()
            };

            await _repo.UpdateGame(game);

            return(RedirectToAction("Index", "Admin", new { game.ID, game.AdminToken }));
        }