//GET: TeamMembers/AddTeamMembers/4 public ActionResult AddTeamMembers(int id) { Team team = _db.Teams.Find(id); List <Player> players = _db.spPlayers_NotInATeam().ToList(); List <SelectListItem> items = new List <SelectListItem>(); foreach (var player in players) { var item = new SelectListItem { Value = player.id.ToString(), Text = player.FirstName + " " + player.LastName }; items.Add(item); } MultiSelectList playersList = new MultiSelectList(items.OrderBy(i => i.Text), "Value", "Text"); TeamPlayerViewModel tpViewModel = new TeamPlayerViewModel { PlayerList = playersList, Team = team }; return(View(tpViewModel)); }
public IActionResult Edit(TeamPlayerViewModel model, int teamId) { Team team = teamRepository.Teams.FirstOrDefault(c => c.TeamID == teamId); if (ModelState.IsValid) { model.TeamPlayer.Team = team; model.TeamPlayer.Player = playerRepository.Players.FirstOrDefault(p => p.PlayerID == model.SelectedTeamPlayerID); team.Players.Add(model.TeamPlayer); teamRepository.Save(team); TempData["message"] = $"{model.TeamPlayer.Player.FirstName} has been assigned to the team."; return(RedirectToAction("Detail", "Team", new { teamId })); } else { TeamPlayerViewModel modelView = new TeamPlayerViewModel { TeamPlayer = new TeamPlayer { Team = team }, Players = playerRepository.Players.Where(p => p.Club == team.Club).ToList() }; return(View(modelView)); } }
public IActionResult Create(int teamId) { Team team = teamRepository.Teams.FirstOrDefault(c => c.TeamID == teamId); TeamPlayerViewModel model = new TeamPlayerViewModel { TeamPlayer = new TeamPlayer { Team = team }, Players = playerRepository.Players.Where(p => p.Club == team.Club).ToList() }; return(View("Edit", model)); }
public void CreateNewPlayer(TeamPlayerViewModel player) { var newPlayer = new TeamPlayer() { TeamId = player.TeamId, TeamIdShort = player.TeamIdShort, PlayerId = player.PlayerId, PlayerName = player.PlayerName, FullName = player.FullName, Country = player.Country }; _genericTeamPlayerRepository.Insert(newPlayer, "TeamPlayers"); }
public ActionResult AddTeamMembers(int id, [Bind(Include = "Name, PlayerId")] TeamPlayerViewModel model) { List <Player> selectedPlayers = new List <Player>(); if (model.PlayerId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } else { model.Team = _db.Teams.Find(id); foreach (var playerId in model.PlayerId) { var idOFPlayer = int.Parse(playerId); model.Players.Add((from p in _db.Players where p.id == idOFPlayer select p).First()); } } if (ModelState.IsValid) { var maxPlayersInATeam = 15; if (model.Team.TeamMembers.Count + model.Players.Count < maxPlayersInATeam) { TeamLogic tL = new TeamLogic(); tL.AddPlayerToTeamList(model.Players, model.Team); tL.UpdateTeamsRatings(model.Team.id); } else { return(View("TooManyPlayersSelected", model.Team)); } } return(RedirectToAction("Details", "Teams", new { id })); }
public void PostNewPlayer(TeamPlayerViewModel player) { _teamPlayerRepository.CreateNewPlayer(player); }