コード例 #1
0
        private int?CreateBoardGameGeekGameDefinition(int?boardGameGeekGameDefinitionId, ApplicationUser currentUser)
        {
            if (boardGameGeekGameDefinitionId.HasValue)
            {
                boardGameGeekGameDefinitionId = boardGameGeekGameDefinitionCreator.CreateBoardGameGeekGameDefinition(
                    boardGameGeekGameDefinitionId.Value, currentUser);
            }

            return(boardGameGeekGameDefinitionId);
        }
コード例 #2
0
        private BoardGameGeekGameDefinition CreateBoardGameGeekGameDefinition(int?boardGameGeekGameDefinitionId)
        {
            BoardGameGeekGameDefinition newBoardGameGeekGameDefinition = null;

            if (boardGameGeekGameDefinitionId.HasValue)
            {
                newBoardGameGeekGameDefinition = _boardGameGeekGameDefinitionCreator.CreateBoardGameGeekGameDefinition(
                    boardGameGeekGameDefinitionId.Value);
            }

            return(newBoardGameGeekGameDefinition);
        }
コード例 #3
0
        private BoardGameGeekGameDefinition CreateBoardGameGeekGameDefinition(int?boardGameGeekGameDefinitionId, ApplicationUser currentUser)
        {
            BoardGameGeekGameDefinition newBoardGameGeekGameDefinition = null;

            if (boardGameGeekGameDefinitionId.HasValue)
            {
                newBoardGameGeekGameDefinition = _boardGameGeekGameDefinitionCreator.CreateBoardGameGeekGameDefinition(
                    boardGameGeekGameDefinitionId.Value);
            }

            return(newBoardGameGeekGameDefinition);
        }
コード例 #4
0
        public override GameDefinition Execute(CreateGameDefinitionRequest createGameDefinitionRequest, ApplicationUser currentUser, IDataContext dataContextWithTransaction)
        {
            ValidateNotNull(createGameDefinitionRequest);

            ValidateGameDefinitionNameIsNotNullOrWhitespace(createGameDefinitionRequest.Name);

            int gamingGroupId = createGameDefinitionRequest.GamingGroupId ?? currentUser.CurrentGamingGroupId;

            BoardGameGeekGameDefinition boardGameGeekGameDefinition = null;

            if (createGameDefinitionRequest.BoardGameGeekGameDefinitionId.HasValue)
            {
                boardGameGeekGameDefinition = _boardGameGeekGameDefinitionCreator.CreateBoardGameGeekGameDefinition(
                    createGameDefinitionRequest.BoardGameGeekGameDefinitionId.Value,
                    currentUser);
            }

            var existingGameDefinition = dataContextWithTransaction.GetQueryable <GameDefinition>()
                                         .FirstOrDefault(game => game.GamingGroupId == gamingGroupId &&
                                                         game.Name == createGameDefinitionRequest.Name);

            if (existingGameDefinition == null)
            {
                var newGameDefinition = new GameDefinition
                {
                    Name = createGameDefinitionRequest.Name,
                    BoardGameGeekGameDefinitionId = boardGameGeekGameDefinition?.Id,
                    Description   = createGameDefinitionRequest.Description,
                    GamingGroupId = gamingGroupId
                };

                new Task(() => _eventTracker.TrackGameDefinitionCreation(currentUser, createGameDefinitionRequest.Name)).Start();

                return(dataContextWithTransaction.Save(newGameDefinition, currentUser));
            }

            ValidateNotADuplicateGameDefinition(existingGameDefinition);

            existingGameDefinition.Active = true;
            existingGameDefinition.BoardGameGeekGameDefinitionId = boardGameGeekGameDefinition?.Id;
            if (!string.IsNullOrWhiteSpace(createGameDefinitionRequest.Description))
            {
                existingGameDefinition.Description = createGameDefinitionRequest.Description;
            }
            return(dataContextWithTransaction.Save(existingGameDefinition, currentUser));
        }