public void ReplacePlayerHistory(IEnumerable<PlayerGlickoHistory> newRankings) { using (var db = new SmashRankingsDatabase()) { using (var dbContext = db.Database.BeginTransaction()) { try { var playerGlickoHistories = newRankings as IList<PlayerGlickoHistory> ?? newRankings.ToList(); var id = playerGlickoHistories.First().TournamentId; var reseedId = playerGlickoHistories.First().PlayerGlickoHistoryId; db.Database.ExecuteSqlCommand($"DBCC CHECKIDENT('PlayerGlickoHistories', RESEED, {reseedId})"); var toRemove = db.PlayerGlickoHistories.Where(x => x.TournamentId == id).ToList(); db.PlayerGlickoHistories.RemoveRange( toRemove ); db.SaveChanges(); db.PlayerGlickoHistories.AddRange(playerGlickoHistories); db.SaveChanges(); reseedId = db.PlayerGlickoHistories.OrderByDescending(x => x.PlayerGlickoHistoryId).First().PlayerGlickoHistoryId; db.Database.ExecuteSqlCommand($"DBCC CHECKIDENT('PlayerGlickoHistories', RESEED, {reseedId})"); dbContext.Commit(); } catch (Exception ex) { dbContext.Rollback(); } } } }
static TournamentDetailsHelper() { Database = new SmashRankingsDatabase(); }
public BaseDbHelper() { Database = new SmashRankingsDatabase(); Database.Configuration.ProxyCreationEnabled = true; }