Esempio n. 1
0
        //TODO need to have validation logic here (or on PlayedGame similar to what is on NewlyCompletedGame)
        public PlayedGame CreatePlayedGame(NewlyCompletedGame newlyCompletedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            if (newlyCompletedGame.GamingGroupId.HasValue && newlyCompletedGame.GamingGroupId != currentUser.CurrentGamingGroupId)
            {
                _securedEntityValidator.RetrieveAndValidateAccess<GamingGroup>(newlyCompletedGame.GamingGroupId.Value, currentUser);
            }

            var gameDefinition = _securedEntityValidator.RetrieveAndValidateAccess<GameDefinition>(newlyCompletedGame.GameDefinitionId, currentUser);

            _linkedPlayedGameValidator.Validate(newlyCompletedGame);

            var gamingGroupId = newlyCompletedGame.GamingGroupId ?? currentUser.CurrentGamingGroupId;

            ValidateAccessToPlayers(newlyCompletedGame.PlayerRanks, gamingGroupId, currentUser);

            var playerGameResults = MakePlayerGameResults(newlyCompletedGame, gameDefinition.BoardGameGeekGameDefinitionId);

            var playedGame = TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                gamingGroupId,
                currentUser.Id,
                playerGameResults);

            playedGame = _dataContext.Save(playedGame, currentUser);

            CreateApplicationLinkages(newlyCompletedGame.ApplicationLinkages, playedGame.Id);

            DoPostSaveStuff(transactionSource, currentUser, playedGame.Id, playedGame.GameDefinitionId, playerGameResults);

            return playedGame;
        }
Esempio n. 2
0
        public PlayedGame UpdatePlayedGame(UpdatedGame updatedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            if (updatedGame.GamingGroupId.HasValue)
            {
                _securedEntityValidator.RetrieveAndValidateAccess <GamingGroup>(updatedGame.GamingGroupId.Value, currentUser);
            }
            _securedEntityValidator.RetrieveAndValidateAccess <PlayedGame>(updatedGame.PlayedGameId, currentUser);
            _securedEntityValidator.RetrieveAndValidateAccess <GameDefinition>(updatedGame.GameDefinitionId, currentUser);

            var playedGameWithStuff = _dataContext.GetQueryable <PlayedGame>()
                                      .Where(x => x.Id == updatedGame.PlayedGameId)
                                      .Include(x => x.ApplicationLinkages)
                                      .Include(x => x.GameDefinition)
                                      .Include(x => x.PlayerGameResults)
                                      .FirstOrDefault();

            if (playedGameWithStuff == null)
            {
                throw new EntityDoesNotExistException(typeof(PlayedGame), updatedGame.PlayedGameId);
            }

            var gamingGroupId = updatedGame.GamingGroupId ?? playedGameWithStuff.GamingGroupId;

            ValidateAccessToPlayers(updatedGame.PlayerRanks, gamingGroupId, currentUser, _dataContext);

            var playerGameResults = MakePlayerGameResults(updatedGame, playedGameWithStuff.GameDefinition?.BoardGameGeekGameDefinitionId, _dataContext);
            var updatedPlayedGame = TransformNewlyCompletedGameIntoPlayedGame(updatedGame, gamingGroupId, currentUser.Id, playerGameResults);

            updatedPlayedGame.Id          = updatedGame.PlayedGameId;
            updatedPlayedGame.DateUpdated = DateTime.UtcNow;

            CleanupPlayerResultsAndApplicationLinkages(currentUser, playedGameWithStuff);

            var returnPlayedGame = _dataContext.Save(updatedPlayedGame, currentUser);

            //--Entity Framework doesn't appear to save new child entities when updating the parent entity so we have to save them separately
            playerGameResults.ForEach(x =>
            {
                x.PlayedGameId = returnPlayedGame.Id;
                _dataContext.Save(x, currentUser);
            });

            CreateApplicationLinkages(updatedGame.ApplicationLinkages, updatedGame.PlayedGameId, _dataContext);

            var playerIds = playerGameResults.Select(x => x.PlayerId).ToList();

            _businessLogicEventSender.SendEvent(new PlayedGameCreatedEvent(
                                                    updatedGame.PlayedGameId,
                                                    updatedGame.GameDefinitionId,
                                                    playerIds,
                                                    transactionSource,
                                                    currentUser));

            return(returnPlayedGame);
        }
Esempio n. 3
0
        public GamingGroupWithUsers GetGamingGroupWithUsers(int gamingGroupId, ApplicationUser currentUser)
        {
            var gamingGroup = _securedEntityValidator.RetrieveAndValidateAccess <GamingGroup>(gamingGroupId, currentUser);

            var users = _dataContext.GetQueryable <Player>()
                        .Where(x => x.GamingGroupId == gamingGroupId && x.ApplicationUserId != null)
                        .Select(x => new BasicUserInfo
            {
                UserName   = x.User.UserName,
                PlayerName = x.Name,
                Email      = x.User.Email,
                Active     = x.Active
            })
                        .OrderByDescending(x => x.Active)
                        .ThenBy(x => x.UserName)
                        .ToList();

            return(new GamingGroupWithUsers
            {
                GamingGroupId = gamingGroup.Id,
                GamingGroupName = gamingGroup.Name,
                Active = gamingGroup.Active,
                PublicDescription = gamingGroup.PublicDescription,
                PublicGamingGroupWebsite = gamingGroup.PublicGamingGroupWebsite,
                OtherUsers = users
            });
        }
        public override PlayedGame Execute(NewlyCompletedGame newlyCompletedGame, ApplicationUser currentUser, IDataContext dataContext)
        {
            var gamingGroupId = ValidateAndGetGamingGroupId(newlyCompletedGame.GamingGroupId, currentUser);

            var gameDefinition = _securedEntityValidator.RetrieveAndValidateAccess <GameDefinition>(newlyCompletedGame.GameDefinitionId, currentUser);

            _linkedPlayedGameValidator.Validate(newlyCompletedGame);

            _playedGameSaver.ValidateAccessToPlayers(newlyCompletedGame.PlayerRanks, gamingGroupId, currentUser, dataContext);

            var playerGameResults = _playedGameSaver.MakePlayerGameResults(newlyCompletedGame, gameDefinition.BoardGameGeekGameDefinitionId, dataContext);

            var playedGame = _playedGameSaver.TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                gamingGroupId,
                currentUser.Id,
                playerGameResults);

            playedGame = dataContext.Save(playedGame, currentUser);

            _playedGameSaver.CreateApplicationLinkages(newlyCompletedGame.ApplicationLinkages, playedGame.Id, dataContext);

            PostExecuteAction = () =>
            {
                return(_businessLogicEventSender.SendEvent(
                           new PlayedGameCreatedEvent(playedGame.Id,
                                                      playedGame.GameDefinitionId,
                                                      playerGameResults.Select(x => x.PlayerId).ToList(),
                                                      newlyCompletedGame.TransactionSource,
                                                      currentUser)));
            };

            return(playedGame);
        }
Esempio n. 5
0
        public override void Execute(int gamingGroupId, ApplicationUser currentUser, IDataContext dataContext)
        {
            _dataContext.SetCommandTimeout(300);

            var gamingGroup =
                _securedEntityValidator.RetrieveAndValidateAccess <GamingGroup>(gamingGroupId, currentUser);

            DeletePlayerGameResults(gamingGroupId, currentUser);
            DeletePlayedGames(gamingGroupId, currentUser);
            DeletePlayerAchievements(gamingGroupId, currentUser);
            DeleteChampionsAndGameDefinitions(gamingGroupId, currentUser);
            DeleteNemeses(gamingGroupId, currentUser);
            DeletePlayers(gamingGroup, currentUser);
            UnassociateUsers(gamingGroupId, currentUser);
            DeleteGamingGroupInvitations(gamingGroupId, currentUser);
            DeleteGamingGroup(gamingGroupId, currentUser);
            _dataContext.CommitAllChanges();
        }