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"); }
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); }