Beispiel #1
0
        private int UpdateCompetitionGames(FixturesList games, int competitionId)
        {
            int updateCount = 0;

            foreach (var game in games.Fixtures)
            {
                var gameStatus = (GameStatus)Enum.Parse(typeof(GameStatus), game.Status.Replace("_", string.Empty), true);
                if (gameStatus == GameStatus.Finished)
                {
                    int homeTeamId = ExtractIdFromLinkItem(game._links.HomeTeam);
                    int awayTeamId = ExtractIdFromLinkItem(game._links.AwayTeam);
                    var gameEntity = _context.Games.FirstOrDefault(g => g.HomeTeamId == homeTeamId &&
                                                                   g.AwayTeamId == awayTeamId && g.Status != GameStatus.Finished);
                    if (gameEntity != null)
                    {
                        gameEntity.AwayTeamGoals     = game.Result.GoalsAwayTeam;
                        gameEntity.HomeTeamGoals     = game.Result.GoalsHomeTeam;
                        gameEntity.HalfAwayTeamGoals = game.Result.HalfTime?.GoalsAwayTeam;
                        gameEntity.HalfHomeTeamGoals = game.Result.HalfTime?.GoalsHomeTeam;
                        gameEntity.MatchDate         = game.Date.Value;
                        gameEntity.MatchDay          = game.Matchday.Value;
                        gameEntity.Status            = gameStatus;

                        _context.Entry(gameEntity).State = EntityState.Modified;
                        updateCount++;
                    }
                }
            }
            _context.SaveChanges();
            return(updateCount);
        }
        public IExternalData GetData(Stream stream)
        {
            FixturesList fixtures = null;

            using (StreamReader reader = new StreamReader(stream))
            {
                JsonSerializer serializer = new JsonSerializer();
                fixtures = (FixturesList)serializer.Deserialize(reader, typeof(FixturesList));
            }
            return(fixtures);
        }
        public IExternalData GetData(string url)
        {
            FixturesList res = new FixturesList();

            using (var client = new HttpClient())
            {
                var response     = client.GetStringAsync(url);
                var stringResult = response.Result;
                res = JsonConvert.DeserializeObject <FixturesList>(stringResult);
            }
            return(res);
        }
Beispiel #4
0
        private void SaveCompetitionGames(FixturesList games, int competitionId)
        {
            List <GameEntity> gameEnitites = new List <GameEntity>();

            foreach (var game in games.Fixtures)
            {
                GameEntity entity = new GameEntity()
                {
                    CompetitionId     = competitionId,
                    AwayTeamGoals     = game.Result.GoalsAwayTeam,
                    HomeTeamGoals     = game.Result.GoalsHomeTeam,
                    HalfAwayTeamGoals = game.Result.HalfTime?.GoalsAwayTeam,
                    HalfHomeTeamGoals = game.Result.HalfTime?.GoalsHomeTeam,
                    MatchDate         = game.Date.Value,
                    MatchDay          = game.Matchday.Value,
                    Status            = (GameStatus)Enum.Parse(typeof(GameStatus), game.Status.Replace("_", string.Empty), true),
                    HomeTeamId        = ExtractIdFromLinkItem(game._links.HomeTeam),
                    AwayTeamId        = ExtractIdFromLinkItem(game._links.AwayTeam)
                };
                gameEnitites.Add(entity);
            }
            _context.Games.AddRange(gameEnitites);
            _context.SaveChanges();
        }