public static List <Season> GetActiveSeasons(DateTimeOffset dateTime) { using (var db = new EloDbContext()) { return(db.Seasons.Where(s => s.IsActive(dateTime)).ToList()); } }
public static List <Season> GetCompletedSeasons(DateTimeOffset dateTime) { using (var db = new EloDbContext()) { return(db.Seasons.Where(s => s.HasEnded(dateTime)).ToList()); } }
public static List <Season> GetAllSeasons() { using (var db = new EloDbContext()) { return(db.Seasons.ToList()); } }
public static Season GetSeason(string name) { using (var db = new EloDbContext()) { return(db.Seasons.FirstOrDefault(s => s.Name == name)); } }
public static void UpdatePlayerSeasons(IEnumerable <PlayerSeason> playerSeasons) { using (var db = new EloDbContext()) { db.PlayerSeasons.UpdateRange(playerSeasons); db.SaveChanges(); } }
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(); } }
public static void DeleteAllPlayerSeasons() { using (var db = new EloDbContext()) { db.PlayerSeasons.RemoveRange(db.PlayerSeasons); db.SaveChanges(); } }
public static void AddRating(PlayerRating rating) { using (var db = new EloDbContext()) { db.Ratings.Add(rating); db.SaveChanges(); } }
public static void AddRatings(IEnumerable <PlayerRating> ratings) { using (var db = new EloDbContext()) { db.Ratings.AddRange(ratings); db.SaveChanges(); } }
public static void DeletePlayers(IEnumerable <Player> players) { using (var db = new EloDbContext()) { db.Players.RemoveRange(players); db.SaveChanges(); } }
public static void DeleteGame(Game game) { using (var db = new EloDbContext()) { db.Games.Remove(game); db.SaveChanges(); } }
public static Player GetPlayerByName(string name) { using (var db = new EloDbContext()) { return(db.Players .Include(p => p.Seasons) .FirstOrDefault(p => p.Name == name)); } }
public static List <Player> GetAllPlayers() { using (var db = new EloDbContext()) { return(db.Players .Include(p => p.Seasons) .ToList()); } }
public static Player GetPlayerById(int id) { using (var db = new EloDbContext()) { return(db.Players .Include(p => p.Seasons) .FirstOrDefault(p => p.Id == id)); } }
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>()); } }
public static PlayerSeason AddPlayerSeason(PlayerSeason playerSeason) { using (var db = new EloDbContext()) { db.PlayerSeasons.Add(playerSeason); db.SaveChanges(); } return(playerSeason); }
public static Game AddGame(Game game) { using (var db = new EloDbContext()) { db.Games.Add(game); db.SaveChanges(); } return(game); }
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()); } }
public static List <string> GetAllPlayerNames() { using (var db = new EloDbContext()) { return(db.Players .Select(p => p.Name) .OrderBy(p => p) .ToList()); } }
public static Player AddPlayer(Player player) { using (var db = new EloDbContext()) { db.Players.Add(player); db.SaveChanges(); } return(player); }
public static Season AddSeason(Season season) { using (var db = new EloDbContext()) { db.Seasons.Add(season); db.SaveChanges(); } return(season); }
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)); } }
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()); } }
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()); } }
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()); } }
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()); } }
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()); } }