Beispiel #1
0
        protected override async Task <BioQuery <Post <string> > > ApplyPublishConditionsAsync(BioQuery <Post <string> > query)
        {
            var currentUser = _currentUserProvider.CurrentUser;

            if (currentUser != null)
            {
                if ((await _authorizationService.AuthorizeAsync(User, PostsPolicies.Posts)).Succeeded)
                {
                    return(query);
                }

                return(query.Where(e => e.IsPublished || e.AuthorId == currentUser.Id));
            }

            return(await base.ApplyPublishConditionsAsync(query));
        }
Beispiel #2
0
        public static BioQuery <T> WithTags <T>(this BioQuery <T> query, Tag[] tags)
            where T : class, IEntity, IContentItem
        {
            Expression <Func <T, bool> >?ex = null;

            foreach (var tag in tags)
            {
                ex = ex == null ? post => post.TagIds.Contains(tag.Id) : ex.And(post => post.TagIds.Contains(tag.Id));
            }

            if (ex != null)
            {
                query = query.Where(ex);
            }

            return(query);
        }
Beispiel #3
0
 public static BioQuery <T> ForSection <T>(this BioQuery <T> query, Section section)
     where T : class, IEntity, ISectionEntity
 {
     return(query.Where(e => e.SectionIds.Contains(section.Id)));
 }
Beispiel #4
0
 public static BioQuery <T> ForSite <T>(this BioQuery <T> query, [NotNull] Site site)
     where T : class, IEntity, ISiteEntity
 {
     return(query.Where(e => e.SiteIds.Contains(site.Id)));
 }
Beispiel #5
0
 protected virtual Task <BioQuery <TEntity> > ApplyPublishConditionsAsync(BioQuery <TEntity> query)
 {
     return(Task.FromResult(query.Where(e => e.IsPublished)));
 }