private IQueryable <Post> GetFilteredQuery(IQueryable <Post> query, PostQueryParams bookQueryParams) { if (!string.IsNullOrEmpty(bookQueryParams.SearchTerm)) { var splitTerm = bookQueryParams.SearchTerm.Split(" "); var paramExpr = Expression.Parameter(typeof(Post), "post"); var titlePropertyExpr = Expression.PropertyOrField(paramExpr, "Title"); var bodyPropertyExpr = Expression.PropertyOrField(paramExpr, "Body"); var methodContains = typeof(string).GetMethod("Contains", new[] { typeof(string) }); var callTitleExpr = Expression.Call(titlePropertyExpr, methodContains, Expression.Constant(bookQueryParams.SearchTerm)); var callBodyExpr = Expression.Call(bodyPropertyExpr, methodContains, Expression.Constant(bookQueryParams.SearchTerm)); var binaryExrp = Expression.OrElse(callTitleExpr, callBodyExpr); Expression <Func <Post, bool> > lambda; if (splitTerm.Length > 1) { foreach (var term in splitTerm) { ConstantExpression constant = Expression.Constant(term, typeof(string)); MethodCallExpression methodCall = Expression.Call(titlePropertyExpr, methodContains, constant); MethodCallExpression methodCall1 = Expression.Call(bodyPropertyExpr, methodContains, constant); binaryExrp = Expression.OrElse(binaryExrp, methodCall); binaryExrp = Expression.OrElse(binaryExrp, methodCall1); } } lambda = Expression.Lambda <Func <Post, bool> >(binaryExrp, new[] { paramExpr }); Console.WriteLine(lambda.ToString()); query = query.Where(lambda); } return(query); }
public Post GetPostBySlug(string slug, PostQueryParams queryParams = null) { var request = new RestRequest($"posts/slug/{slug}/", Method.GET); ApplyPostQueryParams(request, queryParams); return(Execute <PostResponse>(request)?.Posts?.Single()); }
public PageResponse GetPages(PostQueryParams queryParams = null) { var request = new RestRequest("pages/", Method.GET); ApplyPageQueryParams(request, queryParams); return(SetDefaultValues(Execute <PageResponse>(request))); }
public PostResponse GetPosts(PostQueryParams queryParams = null) { var request = new RestRequest("posts/", Method.GET); ApplyPostQueryParams(request, queryParams); return(Execute <PostResponse>(request)); }
public Post GetPageBySlug(string slug, PostQueryParams queryParams = null) { var request = new RestRequest($"pages/slug/{slug}/", Method.GET); ApplyPageQueryParams(request, queryParams); return(SetDefaultValues(Execute <PageResponse>(request)?.Pages?.Single())); }
public Post GetPageById(string id, PostQueryParams queryParams = null) { var request = new RestRequest($"pages/{id}/", Method.GET); ApplyPageQueryParams(request, queryParams); return(Execute <PageResponse>(request)?.Pages?.Single()); }
public Post GetPostById(string id, PostQueryParams queryParams = null) { var request = new RestRequest($"posts/{id}/", Method.GET); ApplyPostQueryParams(request, queryParams); return(SetDefaultValues(Execute <PostResponse>(request)?.Posts?.Single())); }
/// <summary> /// Applies any specified parameters to the post request. /// </summary> /// <param name="request">A post REST request.</param> /// <param name="queryParams">Query parameters.</param> private void ApplyPostQueryParams(RestRequest request, PostQueryParams queryParams) { if (queryParams != null) { if (queryParams.IncludeAuthors && queryParams.IncludeTags) { request.AddQueryParameter("include", "authors,tags"); } else if (queryParams.IncludeAuthors) { request.AddQueryParameter("include", "authors"); } else if (queryParams.IncludeTags) { request.AddQueryParameter("include", "tags"); } if (queryParams.Fields != 0) { request.AddQueryParameter("fields", Ext.GetQueryStringFromFlagsEnum <PostFields>(queryParams.Fields)); } if (queryParams.Fields2 != 0) { request.AddQueryParameter("fields", Ext.GetQueryStringFromFlagsEnum <PostFields2>(queryParams.Fields)); } if (!string.IsNullOrWhiteSpace(queryParams.Filter)) { request.AddQueryParameter("filter", queryParams.Filter); } if (queryParams.Formats != 0) { request.AddQueryParameter("formats", Ext.GetQueryStringFromFlagsEnum <PostFormat>(queryParams.Formats)); } if (queryParams.NoLimit) { request.AddQueryParameter("limit", "all"); } else if (queryParams.Limit > 0) { request.AddQueryParameter("limit", queryParams.Limit.ToString()); } if (queryParams.Page > 0) { request.AddQueryParameter("page", queryParams.Page.ToString()); } if (queryParams.Order?.Any() == true) { request.AddQueryParameter("order", Ext.GetOrderQueryString(queryParams.Order)); } } }
public async Task <PaginationDto <PostGetDto> > GetAllAsync(PostQueryParams queryParams) { var posts = _postRepository.GetAll(); posts = posts.Include(p => p.User).Include(p => p.Tags).ThenInclude(p => p.Tag); if (queryParams.SortableParams != null) { posts = posts.OrderBy(queryParams.SortableParams); } posts = GetFilteredQuery(posts, queryParams); var page = await _paginationService.GetPageAsync <PostGetDto, Post>(posts, queryParams); return(page); }
/// <summary> /// Get a specific page based on its slug. /// </summary> /// <returns>The page matching the given slug. By default, returns MobileDoc format and author and tag data.</returns> /// <param name="slug">The slug of the page to retrieve.</param> /// <param name="queryParams">Parameters that affect the resultset.</param> public new Post GetPageBySlug(string slug, PostQueryParams queryParams = null) { return(base.GetPageBySlug(slug, queryParams)); }
/// <summary> /// Get a specific page based on its ID. /// </summary> /// <returns>The page matching the given ID. By default, returns MobileDoc format and author and tag data.</returns> /// <param name="id">The ID of the page to retrieve.</param> /// <param name="queryParams">Parameters that affect the resultset.</param> public new Page GetPageById(string id, PostQueryParams queryParams = null) { return(base.GetPageById(id, queryParams)); }
/// <summary> /// Get a collection of published pages, /// including meta data about pagination so you can retrieve data in chunks. /// </summary> /// <returns>The pages.</returns> /// <param name="queryParams">Parameters that affect the resultset.</param> public new PageResponse GetPages(PostQueryParams queryParams = null) { return(base.GetPages(queryParams)); }
public async Task <ActionResult <PaginationDto <PostGetDto> > > GetPosts([FromQuery] PostQueryParams param) { var paginationDto = await _postService.GetAllAsync(param); return(paginationDto); }
/// <summary> /// Applies any specified parameters to the page request. /// </summary> /// <param name="request">A page REST request.</param> /// <param name="queryParams">Query parameters.</param> void ApplyPageQueryParams(RestRequest request, PostQueryParams queryParams) { ApplyPostQueryParams(request, queryParams); }