示例#1
0
        public IEnumerable <Season> GetSeasons()
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var query = db.Seasons.OrderByDescending(x => x.EndYear).ThenByDescending(x => x.StartYear).ToList();

                    if (query != null)
                    {
                        return(query);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting Seasons from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(null);
            }
        }
示例#2
0
        public bool CreateSeason(int sy, int ey)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    Season season = new Season()
                    {
                        Name       = "Época " + sy.ToString() + "/ " + ey.ToString(),
                        StartYear  = sy,
                        EndYear    = ey,
                        CreateDate = DateTime.Now
                    };

                    db.Seasons.Add(season);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating new season -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#3
0
        public IEnumerable <Competition> GetCompetitions()
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var query = db.Competitions.OrderBy(x => x.Name).ToList();

                    if (query != null)
                    {
                        return(query);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting Competitions from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(null);
            }
        }
示例#4
0
        public bool ChangeFavoriteValue(int teamId, bool newVal)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var team = db.Teams.Where(x => x.TeamId == teamId).FirstOrDefault();

                    if (team != null)
                    {
                        team.IsFavorite = newVal;
                        db.SaveChanges();
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error changing favorite team from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#5
0
        public string GetCompetitionSeasonName(int competitionId)
        {
            string output = "";

            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var season = (from c in db.Competitions
                                  join s in db.Seasons on c.SeasonId equals s.SeasonId
                                  where c.CompetitionId == competitionId
                                  select new { s.Name }).FirstOrDefault();

                    if (season != null)
                    {
                        output = season.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting competition season name from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);
            }

            return(output);
        }
示例#6
0
        public bool InsertOrUpdateTimeGoals(ObservableCollection <TimeGoalsModel> dados)
        {
            if (dados == null || dados != null ? dados.Count() < 1 : true)
            {
                return(false);
            }

            try
            {
                using (var db = new SpeedOddsContext())
                {
                    foreach (var item in dados)
                    {
                        if (item.TimeGoalsId.HasValue)
                        {
                            //Update
                            var timeGoal = db.TimeGoals.Where(t => t.TimeGoalsId == item.TimeGoalsId).FirstOrDefault();
                            if (timeGoal != null)
                            {
                                timeGoal.Goal15 = item.Goal15;
                                timeGoal.Goal30 = item.Goal30;
                                timeGoal.Goal45 = item.Goal45;
                                timeGoal.Goal60 = item.Goal60;
                                timeGoal.Goal75 = item.Goal75;
                                timeGoal.Goal90 = item.Goal90;

                                db.SaveChanges();
                            }
                        }
                        else
                        {
                            //Create
                            TimeGoal timeGoal = new TimeGoal()
                            {
                                CompetitionId = item.CompetitionId.Value,
                                TeamId        = item.TeamId.Value,
                                Goal15        = item.Goal15,
                                Goal30        = item.Goal30,
                                Goal45        = item.Goal45,
                                Goal60        = item.Goal60,
                                Goal75        = item.Goal75,
                                Goal90        = item.Goal90
                            };

                            db.TimeGoals.Add(timeGoal);
                            db.SaveChanges();
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error saving TimeGoals in BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#7
0
        public IEnumerable <TimeGoal> GetTimeGoalsByCompetition(int compId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var query = db.TimeGoals.Where(t => t.CompetitionId == compId)
                                .OrderBy(x => x.TeamId)
                                .ToList();

                    if (query != null)
                    {
                        return(query);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting TimeGoals by competition from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(null);
            }
        }
示例#8
0
        public bool CreateTeam(string name, int competitionId, bool isFavorite)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    Team team = new Team()
                    {
                        Name          = name.Trim(),
                        CompetitionId = competitionId,
                        IsFavorite    = isFavorite,
                        CreateDate    = DateTime.Now
                    };

                    db.Teams.Add(team);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating new team -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#9
0
        public bool RemoveTeam(int teamId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var team = db.Teams.Where(x => x.TeamId == teamId).FirstOrDefault();

                    if (team != null)
                    {
                        db.Teams.Remove(team);
                        db.SaveChanges();
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error removing team from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#10
0
        public IEnumerable <Team> GetCompetitionTeams(int competitionId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var query = db.Teams
                                .Where(x => x.CompetitionId == competitionId)
                                .OrderBy(x => x.Name).ThenBy(x => x.CreateDate).ToList();

                    if (query != null)
                    {
                        return(query);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting competition Teams from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(null);
            }
        }
示例#11
0
        public bool CreateCompetition(string name, int seasonId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    Competition comp = new Competition()
                    {
                        Name       = name.Trim(),
                        SeasonId   = seasonId,
                        CreateDate = DateTime.Now
                    };

                    db.Competitions.Add(comp);
                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error creating new competition -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#12
0
        public bool RemoveCompetition(int competitionId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var comp = db.Competitions.Where(x => x.CompetitionId == competitionId).FirstOrDefault();

                    if (comp != null)
                    {
                        db.Competitions.Remove(comp);
                        db.SaveChanges();
                        return(true);
                    }

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error removing competition from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#13
0
        public bool CanDeleteById(int teamId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    return(!db.Matches.Where(m => m.HomeTeamId == teamId || m.AwayTeamId == teamId).Any());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error checking teams in matches from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#14
0
        public bool AlreadyExistsTeam(string name, int competitionId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    return(db.Teams.Where(t => t.Name == name && t.CompetitionId == competitionId).Any());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error checking team -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(true);
            }
        }
示例#15
0
        public bool AlreadyExistsCompetition(string name, int seasonId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    return(db.Competitions.Where(c => c.Name == name.Trim() && c.SeasonId == seasonId).Any());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error checking competition -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(true);
            }
        }
示例#16
0
        public bool AlreadyExistsSeason(int sy, int ey)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    return(db.Seasons.Where(s => s.StartYear == sy && s.EndYear == ey).Any());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error checking season -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(true);
            }
        }
示例#17
0
        public bool CanDeleteById(int competitionId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    return(!db.Teams.Where(t => t.CompetitionId == competitionId).Any());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error checking competitions in teams from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(false);
            }
        }
示例#18
0
        public int GetTeamsNumber()
        {
            int nTeams = 0;

            try
            {
                using (var db = new SpeedOddsContext())
                {
                    nTeams = db.Teams.Count();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error counting teams -> " + ex.ToString());
                Console.WriteLine(ex.Message);
            }

            return(nTeams);
        }
示例#19
0
        public int GetCompetitionsNumber()
        {
            int nCompetitions = 0;

            try
            {
                using (var db = new SpeedOddsContext())
                {
                    nCompetitions = db.Competitions.Count();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error counting competitions -> " + ex.ToString());
                Console.WriteLine(ex.Message);
            }

            return(nCompetitions);
        }
示例#20
0
        public Tuple <IEnumerable <Team>, int> GetFilteredTeams(string filterVal, int?compId, bool?isFav)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var query = db.Teams.OrderBy(x => x.Name).ThenBy(x => x.CreateDate).ToList();

                    if (!String.IsNullOrWhiteSpace(filterVal))
                    {
                        query = query.Where(x => x.Name.IndexOf(filterVal, StringComparison.OrdinalIgnoreCase) != -1).ToList();
                    }
                    if (compId.HasValue)
                    {
                        query = query.Where(x => x.CompetitionId == compId.Value).ToList();
                    }
                    if (isFav.HasValue)
                    {
                        query = query.Where(x => x.IsFavorite == isFav.Value).ToList();
                    }

                    if (query != null)
                    {
                        return(new Tuple <IEnumerable <Team>, int>(query, query.Count()));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting filtered Teams from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);

                return(null);
            }
        }
示例#21
0
        public string GetTeamName(int teamId)
        {
            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var team = db.Teams.Where(x => x.TeamId == teamId).FirstOrDefault();

                    if (team != null)
                    {
                        return(team.Name);
                    }

                    return("");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting team from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);
                return("");
            }
        }
示例#22
0
        public string GetSeasonName(int seasonId)
        {
            string output = "";

            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var season = db.Seasons.Where(x => x.SeasonId == seasonId).FirstOrDefault();

                    if (season != null)
                    {
                        output = season.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting season name from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);
            }

            return(output);
        }
示例#23
0
        public string GetCompetitionName(int competitionId)
        {
            string output = "";

            try
            {
                using (var db = new SpeedOddsContext())
                {
                    var comp = db.Competitions.Where(x => x.CompetitionId == competitionId).FirstOrDefault();

                    if (comp != null)
                    {
                        output = comp.Name;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error getting competition name from BD -> " + ex.ToString());
                Console.WriteLine(ex.Message);
            }

            return(output);
        }