public async Task <IReadOnlyCollection <Genre> > FindAsync(GenreSearchCondition searchCondition, string sortProperty)
        {
            IQueryable <Genre> query = BuildFindQuery(searchCondition);

            query = searchCondition.ListSortDirection == ListSortDirection.Ascending
                ? query.OrderBy(sortProperty)
                : query.OrderByDescending(sortProperty);

            return(await query.Page(searchCondition.Page, searchCondition.PageSize).ToListAsync());
        }
        private IQueryable <Genre> BuildFindQuery(GenreSearchCondition searchCondition)
        {
            IQueryable <Genre> query = dbContext.Genres;

            if (searchCondition.Name.Any())
            {
                foreach (var name in searchCondition.Name)
                {
                    var upperName = name.ToUpper().Trim();
                    query = query.Where(x =>
                                        x.Name != null && x.Name.ToUpper().Contains(upperName));
                }
            }

            return(query);
        }
Example #3
0
        public async Task <PagedResponse <FoundGenreDTO> > Handle(SearchGenreQuery request, CancellationToken cancellationToken)
        {
            GenreSearchCondition searchCondition = new GenreSearchCondition()
            {
                Name          = GetFilterValues(request.SearchCondition.Name),
                Page          = request.SearchCondition.Page,
                PageSize      = request.SearchCondition.PageSize,
                SortDirection = request.SearchCondition.SortDirection,
                SortProperty  = request.SearchCondition.SortProperty
            };

            var sortProperty = GetSortProperty(searchCondition.SortProperty);
            IReadOnlyCollection <Genre> foundGenre = await genreService.FindAsync(searchCondition, sortProperty);

            FoundGenreDTO[] mappedGenre = foundGenre.Select(MapToFoundGenreDTO).ToArray();
            var             totalCount  = await genreService.CountAsync(searchCondition);

            return(new PagedResponse <FoundGenreDTO>
            {
                Items = mappedGenre,
                TotalCount = totalCount
            });
        }
 public async Task <IActionResult> SearchGenre([FromBody] GenreSearchCondition searchCondition, CancellationToken cancellationToken = default)
 {
     return(await ExecuteQueryAsync(new SearchGenreQuery(searchCondition), cancellationToken : cancellationToken));
 }
        public async Task <long> CountAsync(GenreSearchCondition searchCondition)
        {
            IQueryable <Genre> query = BuildFindQuery(searchCondition);

            return(await query.LongCountAsync());
        }