Exemple #1
0
 public static List <Season> GetActiveSeasons(DateTimeOffset dateTime)
 {
     using (var db = new EloDbContext())
     {
         return(db.Seasons.Where(s => s.IsActive(dateTime)).ToList());
     }
 }
Exemple #2
0
 public static List <Season> GetCompletedSeasons(DateTimeOffset dateTime)
 {
     using (var db = new EloDbContext())
     {
         return(db.Seasons.Where(s => s.HasEnded(dateTime)).ToList());
     }
 }
Exemple #3
0
 public static List <Season> GetAllSeasons()
 {
     using (var db = new EloDbContext())
     {
         return(db.Seasons.ToList());
     }
 }
Exemple #4
0
 public static Season GetSeason(string name)
 {
     using (var db = new EloDbContext())
     {
         return(db.Seasons.FirstOrDefault(s => s.Name == name));
     }
 }
Exemple #5
0
 public static void UpdatePlayerSeasons(IEnumerable <PlayerSeason> playerSeasons)
 {
     using (var db = new EloDbContext())
     {
         db.PlayerSeasons.UpdateRange(playerSeasons);
         db.SaveChanges();
     }
 }
Exemple #6
0
 public static void DeleteRatingsAfter(int ratingId, bool deleteDefaultRatings = true)
 {
     using (var db = new EloDbContext())
     {
         db.Ratings.RemoveRange(db.Ratings.Where(r => r.Id > ratingId && (deleteDefaultRatings || r.GameId != null)));
         db.SaveChanges();
     }
 }
Exemple #7
0
 public static void DeleteAllPlayerSeasons()
 {
     using (var db = new EloDbContext())
     {
         db.PlayerSeasons.RemoveRange(db.PlayerSeasons);
         db.SaveChanges();
     }
 }
Exemple #8
0
 public static void AddRating(PlayerRating rating)
 {
     using (var db = new EloDbContext())
     {
         db.Ratings.Add(rating);
         db.SaveChanges();
     }
 }
Exemple #9
0
 public static void AddRatings(IEnumerable <PlayerRating> ratings)
 {
     using (var db = new EloDbContext())
     {
         db.Ratings.AddRange(ratings);
         db.SaveChanges();
     }
 }
Exemple #10
0
 public static void DeletePlayers(IEnumerable <Player> players)
 {
     using (var db = new EloDbContext())
     {
         db.Players.RemoveRange(players);
         db.SaveChanges();
     }
 }
Exemple #11
0
 public static void DeleteGame(Game game)
 {
     using (var db = new EloDbContext())
     {
         db.Games.Remove(game);
         db.SaveChanges();
     }
 }
Exemple #12
0
 public static Player GetPlayerByName(string name)
 {
     using (var db = new EloDbContext())
     {
         return(db.Players
                .Include(p => p.Seasons)
                .FirstOrDefault(p => p.Name == name));
     }
 }
Exemple #13
0
 public static List <Player> GetAllPlayers()
 {
     using (var db = new EloDbContext())
     {
         return(db.Players
                .Include(p => p.Seasons)
                .ToList());
     }
 }
Exemple #14
0
 public static Player GetPlayerById(int id)
 {
     using (var db = new EloDbContext())
     {
         return(db.Players
                .Include(p => p.Seasons)
                .FirstOrDefault(p => p.Id == id));
     }
 }
Exemple #15
0
 public static List <PlayerRating> GetRatingsByPlayerAndSeason(Player player, Season season)
 {
     using (var db = new EloDbContext())
     {
         return(db.PlayerSeasons
                .Include(ps => ps.PlayerRatings)
                .FirstOrDefault(ps => ps.PlayerId == player.Id && ps.SeasonId == season.Id)? // zero or one
                .PlayerRatings ?? new List <PlayerRating>());
     }
 }
Exemple #16
0
        public static PlayerSeason AddPlayerSeason(PlayerSeason playerSeason)
        {
            using (var db = new EloDbContext())
            {
                db.PlayerSeasons.Add(playerSeason);
                db.SaveChanges();
            }

            return(playerSeason);
        }
Exemple #17
0
        public static Game AddGame(Game game)
        {
            using (var db = new EloDbContext())
            {
                db.Games.Add(game);
                db.SaveChanges();
            }

            return(game);
        }
Exemple #18
0
 public static List <PlayerSeason> GetAllPlayerSeasons(int seasonId)
 {
     using (var db = new EloDbContext())
     {
         return(db.PlayerSeasons
                .Where(s => s.SeasonId == seasonId)
                .Include(ps => ps.Player)
                .ToList());
     }
 }
Exemple #19
0
 public static List <string> GetAllPlayerNames()
 {
     using (var db = new EloDbContext())
     {
         return(db.Players
                .Select(p => p.Name)
                .OrderBy(p => p)
                .ToList());
     }
 }
Exemple #20
0
        public static Player AddPlayer(Player player)
        {
            using (var db = new EloDbContext())
            {
                db.Players.Add(player);
                db.SaveChanges();
            }

            return(player);
        }
Exemple #21
0
        public static Season AddSeason(Season season)
        {
            using (var db = new EloDbContext())
            {
                db.Seasons.Add(season);
                db.SaveChanges();
            }

            return(season);
        }
Exemple #22
0
 public static Game GetGame(int id)
 {
     using (var db = new EloDbContext())
     {
         return(db.Games
                .Include(g => g.Scores)
                .ThenInclude(gs => gs.Player)
                .Include(g => g.PlayerRatings)
                .FirstOrDefault(g => g.Id == id));
     }
 }
Exemple #23
0
 public static List <PlayerRating> GetLatestRatingsPerPlayerSeason()
 {
     using (var db = new EloDbContext())
     {
         return(db.Ratings
                .Include(pr => pr.PlayerSeason)
                .ThenInclude(ps => ps.Season)
                .GroupBy(pr => pr.PlayerSeasonId)
                .Select(g => g.OrderByDescending(pr => pr.Id).First()) // take latest rating record
                .ToList());
     }
 }
Exemple #24
0
 public static List <Game> GetGamesAfter(int gameId, SortOrder sortOrder)
 {
     using (var db = new EloDbContext())
     {
         return(db.Games
                .Where(g => g.Id > gameId)
                .Include(g => g.Scores)
                .ThenInclude(gs => gs.Player)
                .OrderBy(g => g.Created, sortOrder)
                .ToList());
     }
 }
Exemple #25
0
 public static List <Game> GetGames(int page, int pageSize, SortOrder sortOrder)
 {
     using (var db = new EloDbContext())
     {
         return(db.Games
                .Include(g => g.Scores)
                .ThenInclude(gs => gs.Player)
                .OrderBy(g => g.Created, sortOrder)
                .Skip((page - 1) * pageSize)
                .Take(pageSize)
                .ToList());
     }
 }
Exemple #26
0
 public static List <Season> GetStartedSeasonsByPlayer(DateTimeOffset dateTime, string playerName)
 {
     using (var db = new EloDbContext())
     {
         return(db.PlayerSeasons
                .Include(ps => ps.Season)
                .Include(ps => ps.Player)
                .ToList()
                .Where(ps => ps.Season.HasStarted(dateTime) && ps.Player.Name == playerName)
                .Select(ps => ps.Season)
                .Distinct()
                .ToList());
     }
 }
Exemple #27
0
 public static List <Game> GetGamesByPlayer(string player, SortOrder sortOrder)
 {
     using (var db = new EloDbContext())
     {
         return(db.GameScores
                .Include(gs => gs.Player)
                .Include(gs => gs.Game)
                .ThenInclude(g => g.Scores)
                .ThenInclude(gs => gs.Player)
                .ToList()
                .Where(gs => gs.Player.Name == player)
                .Select(gs => gs.Game)
                .OrderBy(g => g.Created, sortOrder)
                .ToList());
     }
 }