예제 #1
0
        public virtual async Task AddRangeAsync(IEnumerable <TEntity> entities, Query <TEntity> query)
        {
            if (query.Options.ChecksRights)
            {
                var filter = await RightExpressionsHelper.GetFilterAsync(query);
                await EnsureEntitiesAreLoaded(entities, query, filter);

                var rightFilter = filter.Compile();
                if (!entities.All(rightFilter))
                {
                    throw new ForbiddenException("You do not have the rights to create one of the posted entity");
                }
            }

            StorageService.AddRange(entities);
        }
예제 #2
0
        public virtual async Task AddAsync(TEntity entity, Query <TEntity> query)
        {
            if (query.Options.ChecksRights)
            {
                var filter = await RightExpressionsHelper.GetFilterAsync(query);
                await EnsureEntitiesAreLoaded(entity.Yield(), query, filter);

                var rightFilter = filter.Compile();
                if (!rightFilter(entity))
                {
                    throw new ForbiddenException("You do not have the rights to create the posted entity");
                }
            }

            StorageService.Add(entity);
        }
예제 #3
0
        protected virtual async Task <IQueryable <TEntity> > ApplyRightsAsync(IQueryable <TEntity> entities, Query <TEntity> query)
        {
            var filter = await RightExpressionsHelper.GetFilterAsync(query);

            return(entities.Where(filter));
        }