public IEnumerable <LevelInfo> GetLevels(Game gameBox) { // find all game levels IEnumerable <GameLevel> gameLevels = gameLevelRepository.GetWhere(l => l.GameId == gameBox.GameId); // convert to level info return(gameLevels.Select(GetLevelInfo)); }
public async Task <int> CreateUserLevelAsync(int userId, IEnumerable <int> userWordPairIds) { // TODO rewrite no repo // resolve to word pair IEnumerable <UserWordPair> uwp = userWordPairRepository.GetWhere(u => userWordPairIds.Contains(u.UserWordPairId)); // create if not user game catalog exist Game game = creationRepository.GetWhere(c => c.CreatorId.Equals(userId)).SingleOrDefault(); if (game == null) { game = new Game { CreatorId = userId }; await creationRepository.CreateAsync(game).ConfigureAwait(false); } // add level by WordsPairs int levelsCount = gameLevelRepository.GetWhere(g => g.GameId.Equals(game.GameId)).Count(); var gameLevel = new GameLevel { GameId = game.GameId, Level = levelsCount + 1 }; gameLevel = await gameLevelRepository.CreateAsync(gameLevel).ConfigureAwait(false); // level add words IEnumerable <GameLevelWord> gameLevelWords = uwp.Select(u => new GameLevelWord { GameLevelId = gameLevel.GameLevelId, WordPairId = u.WordPairId }); await gameLevelWordRepository.Create(gameLevelWords.ToArray()).ConfigureAwait(false); // return levelId return(gameLevel.GameLevelId); }