Exemplo n.º 1
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.º 2
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");
        }