Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private void GetScoresForTeams(DALTeams dalTeams, List <Team> teams)
        {
            var maxScore = int.MinValue;
            var minScore = int.MaxValue;

            foreach (var dalTeam in dalTeams._embedded.teams)
            {
                var team = new Team {
                    Id = dalTeam.externalId, Name = dalTeam.description
                };
                //getting scores for teams
                var mazes = GetTeam(team.Id);
                foreach (var maze in mazes)
                {
                    var tempMaze = new Maze {
                        Id = maze.mazeId, Score = maze.score
                    };

                    if (maze.score <= minScore && maze.score != 0)
                    {
                        minScore          = maze.score;
                        tempMaze.BestTeam = true;
                        teams.ForEach(t =>
                        {
                            if (t.Mazes.Any())
                            {
                                var innerMaze = t.Mazes.FirstOrDefault(m => m.Id == maze.mazeId);
                                if (innerMaze != null && innerMaze.Score != maze.score)
                                {
                                    innerMaze.BestTeam = false;
                                }
                            }
                        });
                    }
                    else if (maze.score >= maxScore && maze.score != 0)
                    {
                        maxScore           = maze.score;
                        tempMaze.WorstTeam = true;
                        teams.ForEach(t =>
                        {
                            if (t.Mazes.Any())
                            {
                                var innerMaze = t.Mazes.FirstOrDefault(m => m.Id == maze.mazeId);
                                if (innerMaze != null && innerMaze.Score != maze.score)
                                {
                                    innerMaze.WorstTeam = false;
                                }
                            }
                        });
                    }

                    team.Mazes.Add(tempMaze);
                }
                teams.Add(team);
            }
        }
Exemplo n.º 3
0
        public Team GetTeamById(string Id)
        {
            DALTeams dalTeams = new DALTeams(connectionString);

            return(dalTeams.GetById(Id));
        }
Exemplo n.º 4
0
        // TEAMS METHODS.
        public List <Team> GetAllTeams()
        {
            DALTeams dal = new DALTeams(connectionString);

            return(dal.GetAll());
        }