public IEnumerable <GameInfo> GetGames() { return(from creation in creationRepository.GetWhere(g => g.CreatorId == Game.MainGames).ToList() let creationInfo = creationService.GetCreationInfo(creation.GameId) let russianDescription = creationInfo.Descriptions.GetRus() select new GameInfo { CreatorId = creationInfo.CreatorId ?? 0, GameId = creation.GameId, IsAvailable = true, Title = russianDescription.Title, Description = russianDescription.Description }); }
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); }