Esempio n. 1
0
        public virtual void Delete <TEntity>(TEntity entity, ApplicationUser currentUser) where TEntity : class, EntityWithTechnicalKey
        {
            ISecuredEntityValidator <TEntity> validator = securedEntityValidatorFactory.MakeSecuredEntityValidator <TEntity>();

            validator.ValidateAccess(entity, currentUser, typeof(TEntity), UNKNOWN_ENTITY_ID);
            nemeStatsDbContext.Set <TEntity>().Remove(entity);
        }
Esempio n. 2
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)
        {
            GameDefinition gameDefinition = dataContext.FindById <GameDefinition>(newlyCompletedGame.GameDefinitionId);

            securedEntityValidatorForGameDefinition.ValidateAccess(gameDefinition, currentUser, typeof(GameDefinition), newlyCompletedGame.GameDefinitionId);

            this.ValidateAccessToPlayers(newlyCompletedGame, currentUser);

            List <PlayerGameResult> playerGameResults = TransformNewlyCompletedGamePlayerRanksToPlayerGameResults(newlyCompletedGame);

            PlayedGame playedGame = TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                currentUser.CurrentGamingGroupId,
                currentUser.Id,
                playerGameResults);

            dataContext.Save(playedGame, currentUser);

            playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (PlayerGameResult result in playerGameResults)
            {
                nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            championRecalculator.RecalculateChampion(playedGame.GameDefinitionId, currentUser);

            return(playedGame);
        }
Esempio n. 3
0
        public virtual void DeleteById <TEntity>(object id, ApplicationUser currentUser) where TEntity : class, EntityWithTechnicalKey
        {
            TEntity entityToDelete = FindById <TEntity>(id);

            ISecuredEntityValidator <TEntity> securedEntityValidator = securedEntityValidatorFactory.MakeSecuredEntityValidator <TEntity>();

            securedEntityValidator.ValidateAccess(entityToDelete, currentUser, typeof(TEntity), id);

            nemeStatsDbContext.Set <TEntity>().Remove(entityToDelete);
        }
Esempio n. 4
0
 public virtual void ValidateAccessToPlayers(IEnumerable <PlayerRank> playerRanks, int gamingGroupId, ApplicationUser currentUser, IDataContext dataContext)
 {
     foreach (var playerRank in playerRanks)
     {
         var player = dataContext.FindById <Player>(playerRank.PlayerId);
         if (player.GamingGroupId != gamingGroupId)
         {
             throw new PlayerNotInGamingGroupException(player.Id, gamingGroupId);
         }
         _securedEntityValidator.ValidateAccess(player, currentUser);
     }
 }
Esempio n. 5
0
        //TODO If the passed in TEntity that is new, the Id will not be set until SaveChanges is called
        public virtual TEntity Save <TEntity>(TEntity entity, ApplicationUser currentUser) where TEntity : class, EntityWithTechnicalKey
        {
            ValidateArguments <TEntity>(entity, currentUser);

            if (entity.AlreadyInDatabase())
            {
                //TODO update comments to indicate it can throw an exception
                ISecuredEntityValidator <TEntity> validator = securedEntityValidatorFactory.MakeSecuredEntityValidator <TEntity>();
                //TODO how do I get this to be able to pull the Id from TEntity?
                validator.ValidateAccess(entity, currentUser, typeof(TEntity), UNKNOWN_ENTITY_ID);
            }
            else
            {
                SetGamingGroupIdIfEntityIsSecured <TEntity>(entity, currentUser);
            }

            TEntity savedEntity = AddOrInsertOverride <TEntity>(entity);

            CommitAllChanges();

            return(savedEntity);
        }