public IEnumerable <Board> GenerateLeaderboard(string focusUserId, int focusCount) { var boards = new List <Board>(); var boardNames = new string[] { "Victories", "Defeats", "GameCount" }; int id = 0; using (var db = new StatisticsContext(this.NameOrConnectionString)) { foreach (var boardName in boardNames) { var board = new Board() { Id = ++id, Name = boardName, Scores = null }; board.Scores = db.Database.SqlQuery <Score>( "GenerateBoard @boardName, @count, @focusUserId", new SqlParameter("boardName", boardName), new SqlParameter("count", focusCount), new SqlParameter("focusUserId", focusUserId)).ToArray(); boards.Add(board); } } return(boards); }
public IEnumerable<Board> GenerateLeaderboard(string focusUserId, int focusCount) { var boards = new List<Board>(); var boardNames = new string[] { "Victories", "Defeats", "GameCount" }; int id = 0; using (var db = new StatisticsContext(this.NameOrConnectionString)) { foreach (var boardName in boardNames) { var board = new Board() { Id = ++id, Name = boardName, Scores = null }; board.Scores = db.Database.SqlQuery<Score>( "GenerateBoard @boardName, @count, @focusUserId", new SqlParameter("boardName", boardName), new SqlParameter("count", focusCount), new SqlParameter("focusUserId", focusUserId)).ToArray(); boards.Add(board); } } return boards; }
public UserStats Retrieve(string userId) { UserStats stats = null; using (var db = new StatisticsContext(this.NameOrConnectionString)) { stats = db.Statistics.FirstOrDefault(e => e.UserId.Equals(userId, StringComparison.OrdinalIgnoreCase)); } return(stats); }
public void Save(UserStats stats) { using (var db = new StatisticsContext(this.NameOrConnectionString)) { var old = db.Statistics.FirstOrDefault(e => e.UserId.Equals(stats.UserId, StringComparison.OrdinalIgnoreCase)); if (old != null) { old.Victories = stats.Victories; old.Defeats = stats.Defeats; old.GameCount = stats.GameCount; } else { db.Statistics.Add(stats); } db.SaveChanges(); } }
public void Save(UserStats stats) { using (var db = new StatisticsContext(this.NameOrConnectionString)) { var old = db.Statistics.FirstOrDefault(e => e.UserId.Equals(stats.UserId, StringComparison.OrdinalIgnoreCase)); if (old != null) { old.Victories = stats.Victories; old.Defeats = stats.Defeats; old.GameCount = stats.GameCount; } else { db.Statistics.Add(stats); } db.SaveChanges(); } }
public UserStats Retrieve(string userId) { UserStats stats = null; using (var db = new StatisticsContext(this.NameOrConnectionString)) { stats = db.Statistics.FirstOrDefault(e => e.UserId.Equals(userId, StringComparison.OrdinalIgnoreCase)); } return stats; }