Beispiel #1
0
        public bool UpdateMatches(List <Match> Matches)
        {
            if (Matches is null)
            {
                return(false);
            }

            DALMatches dalMatches = new DALMatches(connectionString);

            dalMatches.Update(Matches);


            return(true);
        }
Beispiel #2
0
        public bool SyncMatchesTierOne()
        {
            DALMatches      dalMatches      = new DALMatches(connectionString);                                     // Object to comunicate with Database.
            ResourceMatches resourceMatches = new ResourceMatches(apiToken);                                        // Object to comunicate with API football-data.org.

            foreach (Competition competition in TierOneCompetitions())                                              // Foreach tier_one competition.
            {
                List <Match> lstInsertMatches = new List <Match>();                                                 // Temporary list to hold insertable matches.
                List <Match> lstUpdateMatches = new List <Match>();                                                 // Temporary list to hold updatable  matches.

                List <Match> lstApiMatches = resourceMatches.GetByCompetition(competition.Id.ToString());           // Get a list of matches by competition from the Api.

                foreach (Match apiMatch in lstApiMatches)                                                           // Foreach match in lstApiMatches.
                {
                    if (apiMatch.HomeTeam.Id == 0 || apiMatch.AwayTeam.Id == 0)                                     // 0 == null. Do not insert or update.
                    {
                        continue;
                    }

                    Match dbMatch = dalMatches.GetById(apiMatch.Id.ToString());                                     // Tries to get the same match from db.

                    if (dbMatch is null)                                                                            // If no match then add match to insertable matches list.
                    {
                        lstInsertMatches.Add(apiMatch);
                    }
                    else                                                                                            // Otherwise
                    {
                        DateTime?apiLastUpdated = NormalizeApiDateTime(apiMatch.LastUpdated);                       // First normalize the datetime that came from the api to our standard.

                        if (dbMatch.LastUpdated != apiLastUpdated.ToString())                                       // if Api Last Update is diferent from the corresponding db value.
                        {
                            lstUpdateMatches.Add(apiMatch);                                                         // Add match to updatable matches list.
                        }
                    }
                }

                if (lstInsertMatches.Count != 0)
                {
                    dalMatches.Insert(lstInsertMatches);
                }
                if (lstUpdateMatches.Count != 0)
                {
                    dalMatches.Update(lstUpdateMatches);
                }
            }

            return(true);
        }