private void CreateBoggleBoxInDb(BoggleBox boggleBox) { var board = new Board() { BoggleBoxId = boggleBox.BoggleBoxId, Letters = boggleBox.Dice.GetLetters() }; using (var context = new BoggleDbContext()) { // Checks if board already exist if (context.Board.Count(b => b.BoggleBoxId == boggleBox.BoggleBoxId) != 0) { return; } try { context.Board.Add(board); context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e); throw; } } }
private Board GetBoardById(Guid boggleBoxId) { using (var context = new BoggleDbContext()) { return((from board in context.Board where board.BoggleBoxId == boggleBoxId select board).FirstOrDefault()); } }
public void CreateGame(Game game) { var boggleGame = new BoggleGame() { Name = game.Name, Score = game.Score, fk_BoggleBoxId = Guid.Parse(game.BoggleBoxId) }; using (var context = new BoggleDbContext()) { context.BoggleGame.Add(boggleGame); context.SaveChanges(); } }
public List <PlayerScore> GetHighscores() { using (var context = new BoggleDbContext()) { var playerScores = (from game in context.BoggleGame select new PlayerScore() { PlayerName = game.Name, Score = game.Score, BoggleBoxId = game.fk_BoggleBoxId }).ToList(); var highscores = playerScores.OrderByDescending(p => p.Score).Take(15).ToList(); return(highscores); } }
public WordController(BoggleDbContext context) { this.context = context; }
public HighscoreController(BoggleDbContext context) { _context = context; }