Beispiel #1
0
        /// <summary>
        /// Attempts to save the given entity while ensuring that the given user has the appropriate security to save the given entity.
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entity"></param>
        /// <param name="currentUser"></param>
        /// <exception cref="UnauthorizedAccessException">Thrown if the user is not allowed to save this entity because the user does not have access to the gaming group.</exception>
        /// <returns></returns>
        public virtual TEntity Save <TEntity>(TEntity entity, ApplicationUser currentUser) where TEntity : class, IEntityWithTechnicalKey
        {
            ValidateArguments(entity, currentUser);

            var validator = securedEntityValidatorFactory.MakeSecuredEntityValidator <TEntity>(this);

            validator.ValidateAccess <TEntity>(entity, currentUser);

            if (!entity.AlreadyInDatabase())
            {
                SetGamingGroupIdIfEntityIsSecured(entity, currentUser);
            }

            var savedEntity = AddOrInsertOverride(entity);

            CommitAllChanges();

            return(savedEntity);
        }
Beispiel #2
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);
        }