/// <summary>
        /// Join new player to existing game
        /// </summary>
        /// <param name="gameBoardKey">Game key (string)</param>
        /// <param name="accountId">Account id from session</param>
        public static void JoinGame(string gameBoardKey, int accountId)
        {
            GameBoard game = _context.GameBoards
                             .Include(g => g.Players)
                             .Where(g => g.Key == gameBoardKey)
                             .FirstOrDefault();

            if (game == null)
            {
                throw new KeyNotFoundException("Game doesn't exist!");
            }
            else if (game.Players.Count >= 2)
            {
                throw new Exception("Only two players on a GameBoard is allowed!");
            }

            Player player;

            NewPlayer(gameBoardKey, accountId, out player);

            game.Players.Add(player);
            game.TurnPlayer = player;

            _context.Update(game);
            _context.SaveChanges();
        }
        public async Task <IActionResult> Edit(int id, [Bind("playerId,playerName")] Player player)
        {
            if (id != player.playerId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(player);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlayerExists(player.playerId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(player));
        }
Beispiel #3
0
        public void Test_Entity_Stat_Modified_On_External_Changes()
        {
            MapSeeding();
            var map = _dbContext.Set <Map>().FirstOrDefault();

            map.ShotCoords.Add(new Coords(1, 2));
            _dbContext.Update(map);
            Assert.AreEqual(EntityState.Modified, _dbContext.Entry(map).State);
        }