private PlayerToTeamAssignmentEntity CreatePlayerAssignment(TeamExt team, PlayerEntity playerEntity, PlayerExt playerExt) { PlayerToTeamAssignmentEntity assignment = new PlayerToTeamAssignmentEntity() { EndDate = playerExt.ContractUntil, JerseyNumber = playerExt.JerseyNumber, PlayerID = playerEntity.PlayerId, TeamID = ExtractIdFromLinks(team._links) }; return(assignment); }
private void SaveTeamPlayers(TeamExt team) { foreach (var playerExt in team.Players.Players) { var nameParts = ExtractPlayerNameParts(playerExt.Name); PlayerEntity player = new PlayerEntity { DateOfBirth = playerExt.DateOfBirth, FirstName = nameParts.Item1, LastName = nameParts.Item2, MarketValue = playerExt.MarketValue, NationalityId = GetNationalityId(playerExt.Nationality), PlayerPositionId = GetPositonId(playerExt.Position) }; _context.Players.Add(player); _context.SaveChanges(); var assignemt = CreatePlayerAssignment(team, player, playerExt); _context.PlayerToTeamAssignments.Add(assignemt); _context.SaveChanges(); } }