コード例 #1
0
 public async Task <ActionResult <SearchResultsVm <BlogPostSrVm[]> > > SearchAsync(
     [FromQuery] SearchBlogPostVm searchBlogPostVm)
 {
     return(await _blogPostsService.SearchBlogPostsAsync(_mapper.Map <BlogPostSc>(searchBlogPostVm)));
 }
コード例 #2
0
        public static async Task <SearchResultsVm <BlogPostSrVm[]> > SearchBlogPostsAsync(this HttpClient client, SearchBlogPostVm searchBlogPostVm, HttpStatusCode expectedStatusCode = HttpStatusCode.OK)
        {
            var query = HttpUtility.ParseQueryString(string.Empty);

            if (searchBlogPostVm.Title != null)
            {
                query[nameof(searchBlogPostVm.Title)] = searchBlogPostVm.Title;
            }
            if (searchBlogPostVm.Status != null)
            {
                query[nameof(searchBlogPostVm.Status)] = searchBlogPostVm.Status.ToString();
            }
            if (searchBlogPostVm.PublishedAtFrom != null)
            {
                query[nameof(searchBlogPostVm.PublishedAtFrom)] = searchBlogPostVm.PublishedAtFrom.ToString();
            }
            if (searchBlogPostVm.PublishedAtTo != null)
            {
                query[nameof(searchBlogPostVm.PublishedAtTo)] = searchBlogPostVm.PublishedAtTo.ToString();
            }

            query[nameof(searchBlogPostVm.CurrentPage)] = searchBlogPostVm.CurrentPage.ToString();
            query[nameof(searchBlogPostVm.PageSize)]    = searchBlogPostVm.PageSize.ToString();

            return(await client.DoGetAsync <SearchResultsVm <BlogPostSrVm[]> >($"{url + "?" + query}", expectedStatusCode));
        }