public IActionResult AddPlayers(AddPlayersViewModel viewModel) { if (ModelState.IsValid) { Player player = new Player(viewModel.FirstName, viewModel.LastName, viewModel.Position); iPlayerRepo.AddPlayerAsync(player).Wait(); //Find players team from the values passed in from the view model schoolID and Gender Team team = iTeamRepo.FindTeam(viewModel.SchoolID, viewModel.Gender); int teamID = team.TeamID; int playerID = player.ID; /* * TeamPlayer teamPlayer = new TeamPlayer(viewModel.startDate, player.ID, team.TeamID); * database.TeamPlayers.Add(teamPlayer); * database.SaveChanges(); */ iTeamPlayerRepo.AddTeamPlayer(viewModel.startDate, playerID, teamID).Wait(); return(RedirectToAction("SearchPlayers")); }//END OF IF STATEMENT else { PopulateDropDownLists(); return(View("~/Views/Players/AddPlayers.cshtml")); } }
public IActionResult AddPlayers() { PopulateDropDownLists(); AddPlayersViewModel viewModel = new AddPlayersViewModel(); return(View("~/Views/Players/AddPlayers.cshtml", viewModel)); }
public IActionResult AddPlayersByCoach(AddPlayersViewModel viewModel) { if (ModelState.IsValid) { Player player = new Player(viewModel.FirstName, viewModel.LastName, viewModel.Position); iPlayerRepo.AddPlayerAsync(player).Wait(); //Find players team coachid string coachID = User.FindFirst(ClaimTypes.NameIdentifier).Value; int playerID = player.ID; int teamID = iTeamRepo.FindTeamIDByCoach(coachID); /* * TeamPlayer teamPlayer = new TeamPlayer(viewModel.startDate, player.ID, team.TeamID); * database.TeamPlayers.Add(teamPlayer); * database.SaveChanges(); */ iTeamPlayerRepo.AddTeamPlayer(viewModel.startDate, playerID, teamID).Wait(); return(RedirectToAction("SearchPlayers")); }//END OF IF STATEMENT else { PopulateDropDownLists(); return(View("~/Views/Players/AddPlayers.cshtml")); } //must have add player working and tested //ALSO create findTeamHelper() //Create TeamPlayerRepo }
public IActionResult AddPlayers(int id) { var team = _teamsService.GetTeamWithPlayers(id); if (team.TeamAdminEmails.Contains(User.Identity.Name)) { var model = new AddPlayersViewModel(); model.TeamId = id; model.CurrentPlayers = team.Players.ToList(); model.PlayersToSelect = _context.Players.Where(x => !model.CurrentPlayers.Contains(x)).ToList(); model.TeamName = team.Name; return(View(model)); } return(NotFound()); }
public async Task <IActionResult> AddPlayers(AddPlayersViewModel model) { if (string.IsNullOrEmpty(model.SelectedPlayerIds)) { ModelState.AddModelError("AddingPlayersNumber", "Morate označiti barem jednog igrača kojeg želite dodati."); var team = _teamsService.GetTeamWithPlayers(model.TeamId); model.TeamId = model.TeamId; model.CurrentPlayers = team.Players.ToList(); model.PlayersToSelect = _context.Players.Where(x => !model.CurrentPlayers.Contains(x)).ToList(); model.TeamName = team.Name; return(View(model)); } var playerIdsString = model.SelectedPlayerIds.Split(',').ToList(); var playerIds = playerIdsString.Select(x => x.Trim()).Select(x => int.Parse(x)).ToList(); var isAdded = await _teamsService.AddPlayersToTeam(playerIds, model.TeamId); return(RedirectToAction("Details", "Teams", new { id = model.TeamId })); }
public IActionResult AddPlayersByCoach() { AddPlayersViewModel viewModel = new AddPlayersViewModel(); return(View("~/Views/Players/AddPlayers.cshtml", viewModel)); }
public ActionResult AddPlayers(AddPlayersViewModel model) { return(View()); }