Exemplo n.º 1
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}");
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage Post(Player newPlayer)
        {
            var repo = new PlayerManager();
            repo.AddPlayerToRepo(newPlayer);

            var response = Request.CreateResponse(HttpStatusCode.Created, newPlayer);

            string uri = Url.Link("DefaultApi", new {id = newPlayer.Id});
            response.Headers.Location = new Uri(uri);

            return response;
        }
Exemplo n.º 3
0
        public ActionResult AddFreeAgentToTeam(int id)
        {
            var teamManager = new TeamManager();
            var playerManager = new PlayerManager();
            var vm = new AddFreeAgentToTeamVM();
            vm.TeamToAddPlayer = teamManager.GetAllTeams().FirstOrDefault(t => t.Id == id);
            vm.TeamToRemovePlayer = teamManager.GetTeamById(0);
               // vm.TeamToRemovePlayer.Players = playerManager.GetAllPlayers().FindAll(p => p.TeamId == 0);
            vm.SetPlayerList(vm.TeamToRemovePlayer.Players);
            vm.SetTeamRoster(vm.TeamToAddPlayer.Players);

            return View(vm);
        }
Exemplo n.º 4
0
        public void DeletePlayerTest()
        {
            var manager = new PlayerManager();
            var _players = manager.GetAllPlayers();
            int count = _players.Count();
            var player2 = _players.FirstOrDefault(p => p.Id == 2);
            var player3 = _players.FirstOrDefault(p => p.Id == 3);
            manager.RemovePlayerById(player2.Id);
            manager.RemovePlayerById(player3.Id);

            bool result = (_players.Count == count - 2);

            Assert.IsTrue(result);

            foreach (var p in _players)
            {
                Console.WriteLine($"{p.Id}, {p.FirstName}, {p.LastName}, {p.Position}");
            }
        }
Exemplo n.º 5
0
        public ActionResult AddFreeAgentToTeam(AddFreeAgentToTeamVM vm)
        {
            var teamManager = new TeamManager();
            var playerManager = new PlayerManager();
            var freeagency = teamManager.GetTeamById(0);
            var team = teamManager.GetAllTeams().FirstOrDefault(t => t.Id == vm.TeamToAddPlayer.Id);
            team.Players.Clear();

            if (vm.PlayersToAdd != null && vm.PlayersToAdd.Count > 0)
            {
                foreach (var playerid in vm.PlayersToAdd)
                {
                    freeagency.Players.RemoveAll(p => p.Id == playerid);
                    team.Players.Add(playerManager.GetPlayerById(playerid));
                    var player = playerManager.GetPlayerById(playerid);
                    player.TeamId = team.Id;
                }
            }

            return RedirectToAction("AddFreeAgentToTeam");
        }
Exemplo n.º 6
0
        public ActionResult ViewPlayer(int id)
        {
            var manager = new PlayerManager();
            var player = manager.GetPlayerById(id);

            return View(player);
        }
Exemplo n.º 7
0
        public ActionResult TradePlayers(TradeVM newvm)
        {
            var teamManager = new TeamManager();
            var playerManager = new PlayerManager();
            newvm.Team1 = teamManager.GetTeamById(newvm.Team1.Id);
            newvm.Team2 = teamManager.GetTeamById(newvm.Team2.Id);
            newvm.Team1.Players.Clear();
            newvm.Team2.Players.Clear();

            if (newvm.Team1PlayersToAdd != null && newvm.Team1PlayersToAdd.Count > 0)
            {
                foreach (var playerid in newvm.Team1PlayersToAdd)
                {
                    newvm.Team1.Players.RemoveAll(p => p.Id == playerid);
                    newvm.Team2.Players.Add(playerManager.GetPlayerById(playerid));
                    var player = playerManager.GetPlayerById(playerid);
                    player.TeamId = newvm.Team2.Id;
                }
            }
            if (newvm.Team2PlayersToAdd != null && newvm.Team2PlayersToAdd.Count > 0)
            {
                foreach (var playerid in newvm.Team2PlayersToAdd)
                {
                    newvm.Team2.Players.RemoveAll(p => p.Id == playerid);
                    newvm.Team1.Players.Add(playerManager.GetPlayerById(playerid));
                    var player = playerManager.GetPlayerById(playerid);
                    player.TeamId = newvm.Team1.Id;
                }
            }

            return RedirectToAction("Teams");
        }
Exemplo n.º 8
0
        public ActionResult Players()
        {
            var manager = new PlayerManager();
            var players = manager.GetAllPlayers();
            players = players.OrderBy(p => p.LastName).ToList();

            return View(players);
        }
Exemplo n.º 9
0
 public ActionResult GetTeamsToTrade(GetTeamsForTradeVM vm)
 {
     var teamManager = new TeamManager();
     var playerManager = new PlayerManager();
     var newvm = new TradeVM();
     newvm.Team1 = teamManager.GetTeamById(vm.Team1ID);
     newvm.Team2 = teamManager.GetTeamById(vm.Team2ID);
     var team1players = playerManager.GetAllPlayers().FindAll(p => p.TeamId == newvm.Team1.Id);
     var team2players = playerManager.GetAllPlayers().FindAll(p => p.TeamId == newvm.Team2.Id);
     newvm.SetTeam1List(team1players);
     newvm.SetTeam2List(team2players);
     return View("TradePlayers", newvm);
 }
Exemplo n.º 10
0
        public ActionResult EditPlayer(Player player)
        {
            if (ModelState.IsValid)
            {
                var manager = new PlayerManager();
                manager.EditPlayer(player);
                return RedirectToAction("Players");
            }

            return View();
        }
Exemplo n.º 11
0
        public ActionResult DeletePlayer(Player player)
        {
            var manager = new PlayerManager();
            manager.RemovePlayerById(player.Id);

            return RedirectToAction("Players");
        }
Exemplo n.º 12
0
        public ActionResult CutPlayerToFreeAgency(CutPlayerToFreeAgencyVM vm)
        {
            var teamManager = new TeamManager();
            var playerManager = new PlayerManager();
            var teamToRemovePlayer = teamManager.GetAllTeams().FirstOrDefault(t => t.Id == vm.TeamToRemovePlayer.Id);
            var team = teamManager.GetAllTeams().FirstOrDefault(t => t.Id == 0);
            team.Players.Clear();

            if (vm.PlayersToAdd != null && vm.PlayersToAdd.Count > 0)
            {
                foreach (var playerid in vm.PlayersToAdd)
                {
                    teamToRemovePlayer.Players.RemoveAll(p => p.Id == playerid);
                    team.Players.Add(playerManager.GetPlayerById(playerid));
                    var player = playerManager.GetPlayerById(playerid);
                    player.TeamId = team.Id;
                }
            }

            return RedirectToAction("CutPlayerToFreeAgency");
        }
Exemplo n.º 13
0
 public ActionResult CutPlayerToFreeAgency(int id)
 {
     var teamManager = new TeamManager();
     var playerManager = new PlayerManager();
     var vm = new CutPlayerToFreeAgencyVM();
     vm.FreeAgency = teamManager.GetTeamById(0);
     vm.TeamToRemovePlayer = teamManager.GetTeamById(id);
     vm.TeamToRemovePlayer.Players = playerManager.GetAllPlayers().FindAll(p => p.TeamId == id);
     vm.SetPlayerList(vm.TeamToRemovePlayer.Players);
     vm.SetFreeAgency(vm.FreeAgency.Players);
     return View(vm);
 }
Exemplo n.º 14
0
 public Player Get(int id)
 {
     var repo = new PlayerManager();
     return repo.GetPlayerById(id);
 }
Exemplo n.º 15
0
 public List<Player> Get()
 {
     var repo = new PlayerManager();
     return repo.GetAllPlayers();
 }