protected async Task <BioQuery <TEntity> > ConfigureQueryAsync(BioQuery <TEntity> query, int page, Func <BioQuery <TEntity>, Task <BioQuery <TEntity> > >?configureQuery = null) { if (ControllerContext.HttpContext.Request.Query.ContainsKey("order")) { query.OrderByString(ControllerContext.HttpContext.Request.Query["order"]); } else { ApplyDefaultOrder(query); } if (page > 0) { Page = page; } else if (ControllerContext.HttpContext.Request.Query.ContainsKey("page")) { Page = int.Parse(ControllerContext.HttpContext.Request.Query["page"]); if (Page < 1) { Page = 1; } } query.ForSite(Site).Paginate(page, ItemsPerPage); if (configureQuery != null) { await configureQuery(query); } return(query); }
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); }
protected BioQuery <TEntity> ConfigureQuery(BioQuery <TEntity> query, int limit, int offset, string order, string filter) { if (!string.IsNullOrEmpty(filter) && filter != "null") { var mod4 = filter.Length % 4; if (mod4 > 0) { filter += new string('=', 4 - mod4); } var data = Convert.FromBase64String(filter); var decodedString = HttpUtility.UrlDecode(Encoding.UTF8.GetString(data)); if (!string.IsNullOrEmpty(decodedString)) { query = query.WhereByString(decodedString); } } if (!string.IsNullOrEmpty(order)) { query = query.OrderByString(order); } if (limit > 0) { query = query.Take(limit); } if (offset > 0) { query = query.Skip(offset); } return(query); }
protected override void ApplyDefaultOrder(BioQuery <Post <TUserPk> > query) { query.OrderByDescending(p => p.IsPublished ? p.DatePublished : p.DateUpdated); }
protected virtual async Task <(TEntity[] items, bool needCount)> DoGetAllAsync(BioQuery <TEntity> query) { var dbQuery = query.BuildQuery(); var needCount = false; if (query.Offset != null) { dbQuery = dbQuery.Skip(query.Offset.Value); needCount = true; } if (query.Limit != null) { dbQuery = dbQuery.Take(query.Limit.Value); needCount = true; } return(await AddIncludes(dbQuery).ToArrayAsync(), needCount); }
public static async Task <(T[] items, int itemsCount)> GetAllAsync <T>(this BioQuery <T> query) where T : class
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))); }
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))); }
protected virtual Task <BioQuery <TEntity> > ApplyPublishConditionsAsync(BioQuery <TEntity> query) { return(Task.FromResult(query.Where(e => e.IsPublished))); }
protected virtual Task <BioQuery <TEntity> > ApplyShowConditionsAsync(BioQuery <TEntity> query) { return(ApplyPublishConditionsAsync(query)); }
protected virtual void ApplyDefaultOrder(BioQuery <TEntity> provider) { provider.OrderByDescending(e => e.DateAdded); }
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)); }