Пример #1
0
        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);
        }