Esempio n. 1
0
        public async Task ProcessRosters(FixtureRosters rosters, FixtureShots shots, FixtureMatchInfo matchInfo, IDbConnection conn)
        {
            var homePlayers = rosters.Home.Values.ToList();
            var awayPlayers = rosters.Away.Values.ToList();
            var players     = homePlayers.Union(awayPlayers).ToList();
            var allShots    = shots.Home.Union(shots.Away).ToList();

            var playerEntities = players.Select(p => new Entities.Player
            {
                Id   = p.PlayerId,
                Name = p.PlayerName
            }).ToList();

            await _playerRepository.InsertPlayersAsync(playerEntities, conn);

            var fixturePlayers = new List <Entities.FixturePlayer>();

            foreach (var player in players)
            {
                var rosterOutPlayer = players.Find(p => p.Id == player.RosterOut);
                var rosterInPlayer  = players.Find(p => p.Id == player.RosterIn);

                var fixturePlayer = new Entities.FixturePlayer
                {
                    ExpectedGoalsBuildup = player.ExpectedGoalsBuildup,
                    ExpectedGoalsChain   = player.ExpectedGoalsChain,
                    Minutes = player.Time,
                    Player  = new Entities.Player {
                        Id = player.PlayerId
                    },
                    Position        = player.Position,
                    PositionOrder   = player.PositionOrder,
                    RedCards        = player.RedCard,
                    YellowCards     = player.YellowCard,
                    Assists         = player.Assists,
                    ExpectedAssists = player.ExpectedAssists,
                    ExpectedGoals   = player.ExpectedGoals,
                    FixtureId       = matchInfo.Id,
                    Goals           = player.Goals,
                    KeyPasses       = player.KeyPasses,
                    OwnGoals        = player.OwnGoals,
                    Shots           = player.Shots,
                    ShotsOnTarget   = allShots.Count(s => s.PlayerId == player.PlayerId && (s.Result == "Goal" || s.Result == "SavedShot")),
                    Replaced        = rosterOutPlayer == null ? null : new Entities.Player {
                        Id = rosterOutPlayer.PlayerId
                    },
                    ReplacedBy = rosterInPlayer == null ? null : new Entities.Player {
                        Id = rosterInPlayer.PlayerId
                    },
                    Team = new Entities.Team {
                        Id = player.TeamId
                    }
                };

                fixturePlayers.Add(fixturePlayer);
            }

            await _fixtureRepository.InsertFixturePlayers(fixturePlayers, conn);
        }
Esempio n. 2
0
        public static Models.v0.FixturePlayerBasic ToModel(this Entities.FixturePlayer entity)
        {
            if (entity == null)
            {
                return(null);
            }

            return(new Models.v0.FixturePlayerBasic
            {
                Minutes = entity.Minutes,
                Player = entity.Player.ToModel(),
                Position = entity.Position,
                RedCards = entity.RedCards,
                YellowCards = entity.YellowCards,
                Assists = entity.Assists,
                Goals = entity.Goals,
                KeyPasses = entity.KeyPasses,
                OwnGoals = entity.OwnGoals,
                Shots = entity.Shots,
                ShotsOnTarget = entity.ShotsOnTarget,
                Team = entity.Team.ToModel()
            });
        }