public async Task <List <BlogDTO> > SearchAsync(BlogSearchDTO blogSearchDTO)
        {
            Preconditions.NotNull(blogSearchDTO, nameof(blogSearchDTO));

            var blogs = await _blogRepository.GetAllWithReferences();

            if (!string.IsNullOrWhiteSpace(blogSearchDTO.Title))
            {
                blogs = blogs.Where(b => b.Title.Contains(blogSearchDTO.Title, System.StringComparison.OrdinalIgnoreCase));
            }

            if (blogSearchDTO.CategoryID.HasValue)
            {
                blogs = blogs.Where(b => b.BlogCategories
                                    .Any(bc => bc.CategoryID.Equals(blogSearchDTO.CategoryID.Value)));
            }

            blogs = OrderBlogs(blogs, blogSearchDTO.SortOrder, blogSearchDTO.BlogOrderBy);

            return(_mapper.Map <List <BlogDTO> >(blogs));
        }
예제 #2
0
        public async Task <List <BlogDTO> > SearchAsync(BlogSearchDTO blogSearchDTO)
        {
            string blogSearchDTOQueryString = blogSearchDTO.ToQueryString();

            return(await _httpService.GetHelperAsync <List <BlogDTO> >($"{BlogClientEndpoints.Search}?{blogSearchDTOQueryString}"));
        }
예제 #3
0
 public async Task <ActionResult <List <BlogDTO> > > Search([FromQuery] BlogSearchDTO blogSearchDTO)
 {
     return(await _blogSearchService.SearchAsync(blogSearchDTO));
 }