Esempio n. 1
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");
        }
Esempio n. 2
0
        public ActionResult ViewPlayer(int id)
        {
            var manager = new PlayerManager();
            var player = manager.GetPlayerById(id);

            return View(player);
        }
Esempio n. 3
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");
        }
Esempio n. 4
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");
        }
Esempio n. 5
0
 public Player Get(int id)
 {
     var repo = new PlayerManager();
     return repo.GetPlayerById(id);
 }