Пример #1
0
        public async Task <Game> AddCreationInfoAsync(CreationInfo creationInfo)
        {
            if (creationInfo.CreatorId == null)
            {
                throw new ArgumentNullException($"{nameof(creationInfo)} creator not found");
            }

            var creation = new Game
            {
                CreatorId = (int)creationInfo.CreatorId
            };

            creation = await CreationRepository.CreateAsync(creation).ConfigureAwait(false);

            IEnumerable <CreationDescription> creationDescriptions = creationInfo.Descriptions.Select(cd =>
                                                                                                      new CreationDescription
            {
                CreationId  = creation.GameId,
                LanguageId  = cd.LangId,
                Title       = cd.Title,
                Description = cd.Description
            });

            await CreationDescriptionRepository.Create(creationDescriptions.ToArray()).ConfigureAwait(false);

            return(creation);
        }
Пример #2
0
        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);
        }