public async Task ProcessShots(FixtureShots shots, FixtureRosters rosters, FixtureMatchInfo matchInfo, IDbConnection conn) { var allShots = shots.Home.Union(shots.Away).ToList(); var homePlayers = rosters.Home.Values.ToList(); var awayPlayers = rosters.Away.Values.ToList(); var entities = new List <Entities.FixtureShot>(); foreach (var shot in allShots) { var entity = new Entities.FixtureShot(); // Try and resolve the assister if there is one if (shot.PlayerAssistedName != null) { FixtureRosterEntry matchingPlayer = null; if (shot.HomeOrAway == "h") { matchingPlayer = homePlayers.Find(v => v.PlayerName == shot.PlayerAssistedName); } else if (shot.HomeOrAway == "a") { matchingPlayer = awayPlayers.Find(p => p.PlayerName == shot.PlayerAssistedName); } if (matchingPlayer != null) { entity.Assist = new Entities.Player { Id = matchingPlayer.PlayerId }; } } entity.ExpectedGoal = shot.ExpectedGoal; entity.ShotId = shot.Id; entity.Player = new Entities.Player { Id = shot.PlayerId }; entity.Minute = shot.Minute; entity.Result = shot.Result; entity.X = shot.X; entity.Y = shot.Y; entity.FixtureId = matchInfo.Id; entity.ExpectedGoal = shot.ExpectedGoal; entity.Team = new Entities.Team { Id = shot.HomeOrAway == "h" ? matchInfo.HomeTeamId : matchInfo.AwayTeamId }; entity.Situation = shot.Situation; entity.Type = shot.ShotType; entity.LastAction = shot.LastAction; entities.Add(entity); } await _fixtureRepository.InsertFixtureShots(entities, conn); }
public static Models.v0.FixtureShot ToModel(this Entities.FixtureShot entity) { if (entity == null) { return(null); } return(new Models.v0.FixtureShot { ExpectedGoal = entity.ExpectedGoal, Team = entity.Team.ToModel(), LastAction = entity.LastAction, Minute = entity.Minute, Player = entity.Player.ToModel(), Assist = entity.Assist.ToModel(), Result = entity.Result, ShotId = entity.ShotId, Situation = entity.Situation, Type = entity.Type, X = entity.X, Y = entity.Y }); }