Example #1
0
 public void EditPlayer(Player player)
 {
     var team = _teamRepository.GetAllTeams().FirstOrDefault(t => t.Id == player.TeamId);
     team.Players.RemoveAll(t => t.Id == player.Id);
     _playerRepo.EditPlayer(player);
     team.Players.Add(player);
 }
Example #2
0
        public void AddPlayerTest()
        {
            var manager = new PlayerManager();

            var _players = manager.GetAllPlayers();

            int count = _players.Count();

            var player = new Player
            {
                FirstName = "Ryan",
                LastName = "Rowe",
                JerseyNumber = 33,
                Position = Positions.P,
                BattingAvg = .500,
                YearsPlayed = 5,
                TeamId = 0,
                LeagueId = 0
            };

            manager.AddPlayerToRepo(player);

            bool result = (_players.Count() == count + 1);

            Assert.IsTrue(result);

            foreach (var p in _players)
            {
                Console.WriteLine($"{p.Id},{p.FirstName},{p.LastName},{p.Position}");
            }
        }
 public void EditPlayer(Player player)
 {
     var selectedPlayer = _players.FirstOrDefault(p => p.Id == player.Id);
     selectedPlayer.BattingAvg = player.BattingAvg;
     selectedPlayer.JerseyNumber = player.JerseyNumber;
     selectedPlayer.FirstName = player.FirstName;
     selectedPlayer.LastName = player.LastName;
     selectedPlayer.Position = player.Position;
     selectedPlayer.YearsPlayed = player.YearsPlayed;
     WriteFile();
 }
Example #4
0
 public void AddPlayerToRepo(Player player)
 {
     if (GetAllPlayers().Count != 0)
     {
         player.Id = GetAllPlayers().LastOrDefault().Id + 1;
     }
     else
     {
         player.Id = 1;
     }
     _playerRepo.AddPlayer(player);
      SetToFreeAgent(player);
 }
Example #5
0
 public ActionResult Create(FormCollection collection)
 {
     Player player = new Player();
     try
     {
         UpdateModel(player, new string[] {"PlayerName"
                                             , "PlayerFirstName"
                                             , "PlayerLastName"
                                             , "PlayerPosition"
                                             , "TeamID"
                                             });
         _playerRepository.Create(player);
         _playerRepository.Save();
         return RedirectToAction("Index");
     }
     catch
     {
         return View(player);
     }
 }
Example #6
0
 public void AddPlayer(Player player)
 {
     _players.Add(player);
 }
 public void AddPlayer(Player player)
 {
     _players.Add(player);
     WriteFile();
 }
Example #8
0
        public ActionResult EditPlayer(Player player)
        {
            if (ModelState.IsValid)
            {
                var manager = new PlayerManager();
                manager.EditPlayer(player);
                return RedirectToAction("Players");
            }

            return View();
        }
Example #9
0
        public ActionResult DeletePlayer(Player player)
        {
            var manager = new PlayerManager();
            manager.RemovePlayerById(player.Id);

            return RedirectToAction("Players");
        }
Example #10
0
        /// <summary>
        /// this method will add players to the free agency
        /// </summary>
        /// <param name="player"></param>
        public void PlayerToFreeAgency(Player player)
        {
            var team = GetTeamById(0);

            team.Players.Add(player);
        }
Example #11
0
 public void TradePlayers(Team team1, Team team2, Player player1, Player player2)
 {
     int x =  player1.TeamId;
     player1.TeamId = player2.TeamId;
     player2.TeamId = x;
     team1.Players.Remove(player1);
     team2.Players.Remove(player2);
     team1.Players.Add(player2);
     team2.Players.Add(player1);
 }
Example #12
0
 //public void CutPlayerById(int id)
 //{
 //    var manager = new TeamManager();
 //    var player = _playerRepo.GetAllPlayers().FirstOrDefault(p => p.Id == id);
 //    var team = manager.GetTeamById(player.TeamId);
 //    team.Players.RemoveAll(p => p.Id == player.Id);
 //    var freeagency = _teamRepository.GetAllTeams().FirstOrDefault(f => f.Id == 0);
 //    freeagency.Players.Add(player);
 //}
 //// public void RemovePlayerFromTeamById(int id)
 // {
 //     var player = GetPlayerById(id);
 //     var team = _teamRepository.GetAllTeams().FirstOrDefault(t => t.Id == player.TeamId);
 //     if (team != null)
 //     {
 //         team.Players.Remove(player);
 //         _teamRepository.EditTeam(team);
 //     }
 //_playerRepo.RemovePlayerById(id);
 //}
 public void AddPlayerToTeam(Player player)
 {
     var team = _teamRepository.GetAllTeams().FirstOrDefault(t => t.Id == player.TeamId);
     team.Players.Add(player);
     _teamRepository.EditTeam(team);
 }
Example #13
0
 public void SetToFreeAgent(Player player)
 {
     player.TeamId = 0;
     var freeagency = _teamRepository.GetAllTeams().FirstOrDefault(t => t.Id == 0);
     freeagency.Players.Add(player);
 }