Esempio n. 1
0
        private void GetMatchesOfLeagueFromApi(League lg)
        {
            GetApiClient();
            var matches = _client.GetMatchesForLeague(lg);
            var repo    = new TeamRepository();
            var mrepo   = new MatchRepository();

            using (var trans = mrepo.OpenTranscation())
            {
                foreach (var m in matches)
                {
                    if (!mrepo.ContainsMatch(m))
                    {
                        m.League   = lg;
                        m.HomeTeam = repo.GetByName(m.HomeTeam.Name);
                        m.AwayTeam = repo.GetByName(m.AwayTeam.Name);
                        mrepo.SaveOrUpdate(m);
                    }
                    else
                    {
                        var oldMatch = mrepo.GetMatch(m);
                        if (oldMatch.AwayTeamScore != m.AwayTeamScore)
                        {
                            oldMatch.AwayTeamScore = m.AwayTeamScore;
                            oldMatch.HomeTeamScore = m.HomeTeamScore;
                            mrepo.SaveOrUpdate(oldMatch);
                        }
                    }
                }
                trans.Commit();
            }
        }
Esempio n. 2
0
        public void UpdateMatchesOfTeam(Team t)
        {
            GetApiClient();
            var mrepo   = new MatchRepository();
            var lrepo   = new LeagueRepository();
            var matches = _client.GetMatchesForTeam(t);

            foreach (var m in matches)
            {
                if (!mrepo.ContainsMatch(m))
                {
                    m.League = lrepo.GetByApiId(m.League.ApiId);
                    if (DateTime.Compare(t.UpdatedAt, m.League.UpdatedAt) <= 0)
                    {
                        if (m.HomeTeam.Name == t.Name)
                        {
                            m.HomeTeam = t;
                            var team = getFromApiById(m.AwayTeam.ApiId);
                            if (team.Discipline == null)
                            {
                                team.Discipline = new DisciplineRepository().GetByName("Football");
                            }
                            if (!ContainsName(team.Name))
                            {
                                SaveOrUpdate(team);
                            }
                            else
                            {
                                team = GetByName(team.Name);
                            }
                            m.AwayTeam = team;
                        }
                        else
                        {
                            var team = getFromApiById(m.HomeTeam.ApiId);
                            if (team.Discipline == null)
                            {
                                team.Discipline = new DisciplineRepository().GetByName("Football");
                            }
                            if (!ContainsName(team.Name))
                            {
                                SaveOrUpdate(team);
                            }
                            else
                            {
                                team = GetByName(team.Name);
                            }
                            m.HomeTeam = team;
                            m.AwayTeam = t;
                        }
                        mrepo.SaveOrUpdate(m);
                    }
                }
                else
                {
                    var oldMatch = mrepo.GetMatch(m);
                    oldMatch.AwayTeamScore = m.AwayTeamScore;
                    oldMatch.HomeTeamScore = m.HomeTeamScore;
                    mrepo.SaveOrUpdate(oldMatch);
                }
            }
            t.UpdatedAt = DateTime.Now;
            SaveOrUpdate(t);
        }