Example #1
0
        public bool SyncTeams()
        {
            ResourceTeams resourceTeams = new ResourceTeams(apiToken);                              // Object to comunicate with API football-data.org.
            DALTeams      dalTeams      = new DALTeams(connectionString);                           // Object to comunicate with Database.

            List <Team> lstInsertTeams = new List <Team>();                                         // Temporary List<Competition> to insert.
            List <Team> lstUpdateTeams = new List <Team>();                                         // Temporary List<Competition> to update.



            foreach (Competition competition in TierOneCompetitions())                              // Foreach tier_one competition.
            {
                List <Team> lstTeams = resourceTeams.GetByCompetition(competition.Id.ToString());   // Get all the teams from the API.


                foreach (Team apiTeam in lstTeams)                                                  // Foreach apiTeam.
                {
                    Team dbTeam = dalTeams.GetById(apiTeam.Id.ToString());                          // Get Team by Id from db.


                    if (dbTeam == null)                                                             // If dbTeam null then add to lstInsertTeams.
                    {
                        if (lstInsertTeams.Find(x => x.Id == apiTeam.Id) is null)                   // But first find out if lstInsertTeams has already dbTeam.
                        {
                            lstInsertTeams.Add(apiTeam);                                            // If not add to lstInsertTeams.
                        }
                        continue;
                    }

                    if (apiTeam.LastUpdated == null)                                                // If apiTeam.LastUpdated == null no need to update.
                    {
                        continue;
                    }

                    DateTime?apiTeamLastUpdated = NormalizeApiDateTime(apiTeam.LastUpdated);

                    if (apiTeamLastUpdated.ToString() != dbTeam.LastUpdated)
                    {
                        lstUpdateTeams.Add(apiTeam);
                    }
                }
            }


            if (lstInsertTeams.Count != 0)
            {
                dalTeams.Insert(lstInsertTeams);
            }
            if (lstUpdateTeams.Count != 0)
            {
                dalTeams.Update(lstUpdateTeams);
            }


            return(true);
        }
Example #2
0
 void Start()
 {
     cooldown     = secondsPerGive;
     team         = GetComponent <Team>();
     resourceTeam = GameObject.FindObjectOfType <ResourceTeams>();
 }
Example #3
0
 void Start()
 {
     team = GetComponentInParent <Team>();
     //cameraCommander = GetComponentInParent<Camera>();
     ResourceTeam = GameObject.FindObjectOfType <ResourceTeams>();
 }
Example #4
0
 void Start()
 {
     BuildingPlacement = GetComponentInChildren <BuildingPlacement>();
     Tooltip           = GetComponentInChildren <Tooltip>();
     ResourceManager   = GameObject.FindObjectOfType <ResourceTeams>();
 }