public ActionResult AddPlayer(string playerId) { AspNetUser currentUser = ORM.AspNetUsers.Single(user => user.Email == User.Identity.Name); Team currentUserTeam = CSharpDbDAL.GetTeam(currentUser.Id); if (currentUserTeam.Players.Count >= 5) { TempData["Message"] = "Only 5 players allowed."; return(RedirectToAction("TeamManagement")); } Player alreadyExistingPlayer = currentUserTeam.Players.SingleOrDefault(p => p.Id == playerId); if (alreadyExistingPlayer != null) { TempData["Message"] = $"{alreadyExistingPlayer.Name} already belongs to team."; return(RedirectToAction("TeamManagement")); } JObject data = CsharpJamApi.GetSportPlayerId(playerId); JArray playerDataArray = (JArray)data["players"]; JObject playerData = (JObject)playerDataArray[0]; UserPlayer userPlayer = new UserPlayer(playerData) { Team = currentUserTeam }; Player player = new Player() { Id = userPlayer.Id, TeamId = userPlayer.TeamId, Name = userPlayer.Name, Skill = userPlayer.Skill, Agility = userPlayer.Agility, Strength = userPlayer.Strength, Endurance = userPlayer.Endurance, Aggression = userPlayer.Aggression, Humor = userPlayer.Humor, TeamWork = userPlayer.TeamWork, Rating = userPlayer.Rating, Height = userPlayer.Height, Weight = userPlayer.Weight, Description = userPlayer.Description, PictureUrl = userPlayer.PictureUrl, Team = userPlayer.Team }; CSharpDbDAL.AddPlayers(player); TempData["Message"] = $"{player.Name} added to team."; return(RedirectToAction("TeamManagement")); }