public void AddGamePlayers(Game newGame) { _repo.Add(new GamePlayer { GameId = newGame.Id, PlayerId = newGame.Player1.Id }); _repo.Add(new GamePlayer { GameId = newGame.Id, PlayerId = newGame.Player2.Id }); }
public void AddHitLocation(HitLocation newHitLocation) { Game currentGame = (from g in _repo.Query <Game>() where g.Id == newHitLocation.Game.Id select g).FirstOrDefault(); newHitLocation.Game = currentGame; _repo.Add(newHitLocation); }
public void AddGame(Game newGame, List <HitLocation> bounces) { Player player1 = (from p in _repo.Query <Player>() where p.Id == newGame.Player1.Id select p).FirstOrDefault(); Player player2 = (from p in _repo.Query <Player>() where p.Id == newGame.Player2.Id select p).FirstOrDefault(); if (newGame.Player1Score > newGame.Player2Score) { player1.Wins++; player2.Losses++; } else { player1.Losses++; player2.Wins++; } _db.SaveChanges(); newGame.Player1 = player1; newGame.Player2 = player2; DateTime myDateTime = DateTime.Now; newGame.CreatedDate = myDateTime; // Add the game to the Games table: _repo.Add(newGame); // Add the players to the GamePlayer table: _gamePlayerSer.AddGamePlayers(newGame); // Add the hit locations (bounces) to the HitLocation table: Game currentGame = new Game { Id = newGame.Id }; foreach (HitLocation hitLocation in bounces) { hitLocation.Game = currentGame; _hitLocationSer.AddHitLocation(hitLocation); } }
public void AddPlayer(Player newPlayer) { _repo.Add(newPlayer); }