public GenericSearchResponse <ThumbnailOption> Search(ThumbnailOptionSearchCriteria criteria)
        {
            using (var repository = this._thumbnailRepositoryFactory())
            {
                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[]
                    {
                        new SortInfo
                        {
                            SortColumn = ReflectionUtility.GetPropertyName <ThumbnailTask>(t => t.CreatedDate), SortDirection = SortDirection.Descending
                        }
                    }
                }
                ;

                var query      = repository.ThumbnailOptions.OrderBySortInfos(sortInfos);
                var totalCount = query.Count();

                var ids     = query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToArray();
                var results = repository.GetThumbnailOptionsByIds(ids).Select(t => t.ToModel(AbstractTypeFactory <ThumbnailOption> .TryCreateInstance())).ToArray();

                var retVal = new GenericSearchResponse <ThumbnailOption>
                {
                    TotalCount = totalCount,
                    Results    = results.AsQueryable().OrderBySortInfos(sortInfos).ToList()
                };

                return(retVal);
            }
        }
    }
Example #2
0
        public SearchResult <ThumbnailOption> Search(ThumbnailOptionSearchCriteria criteria)
        {
            var result = _thumbnailOptionSearchService.Search(criteria);

            var searchResult = new SearchResult <ThumbnailOption>
            {
                Result     = result.Results.ToArray(),
                TotalCount = result.TotalCount
            };

            return(searchResult);
        }
        public void Search_ThumbnailOptionSearchCriteria_ReturnsGenericSearchResponseOfTasksInExpectedOrder()
        {
            var repoMock = GetOptionsRepositoryMock();
            var target   = new ThumbnailOptionSearchService(() => repoMock.Object);
            var criteria = new ThumbnailOptionSearchCriteria {
                Sort = "Name:desc;FileSuffix:desc"
            };
            var resultTasks = target.SearchAsync(criteria).GetAwaiter().GetResult();

            var expectedTasks = ThumbnailTaskEntitysDataSource.Select(x => x.ToModel(new ThumbnailOption())).OrderByDescending(t => t.Name).ThenByDescending(t => t.FileSuffix).ToArray();

            Assert.Equal(expectedTasks, resultTasks.Results);
        }
Example #4
0
        protected virtual IList <SortInfo> BuildSortExpression(ThumbnailOptionSearchCriteria criteria)
        {
            var sortInfos = criteria.SortInfos;

            if (sortInfos.IsNullOrEmpty())
            {
                sortInfos = new[]
                {
                    new SortInfo {
                        SortColumn    = nameof(ThumbnailOptionEntity.ModifiedDate),
                        SortDirection = SortDirection.Descending
                    }
                };
            }

            return(sortInfos);
        }
        public virtual async Task <ThumbnailOptionSearchResult> SearchAsync(ThumbnailOptionSearchCriteria criteria)
        {
            using (var repository = _thumbnailRepositoryFactor())
            {
                var result = AbstractTypeFactory <ThumbnailOptionSearchResult> .TryCreateInstance();

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[]
                    {
                        new SortInfo
                        {
                            SortColumn = ReflectionUtility.GetPropertyName <ThumbnailTask>(t => t.CreatedDate), SortDirection = SortDirection.Descending
                        }
                    }
                }
                ;

                var query      = repository.ThumbnailOptions.OrderBySortInfos(sortInfos);
                var totalCount = await query.CountAsync();

                var results = new ThumbnailOption[0];

                if (criteria.Take > 0)
                {
                    var ids = await query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToArrayAsync();

                    var thumbnailOptions = await repository.GetThumbnailOptionsByIdsAsync(ids);

                    results = thumbnailOptions.Select(t => t.ToModel(AbstractTypeFactory <ThumbnailOption> .TryCreateInstance())).ToArray();
                }

                result.TotalCount = totalCount;
                result.Results    = results.AsQueryable().OrderBySortInfos(sortInfos).ToList();

                return(result);
            }
        }
    }
Example #6
0
        public virtual async Task <ThumbnailOptionSearchResult> SearchAsync(ThumbnailOptionSearchCriteria criteria)
        {
            using (var repository = _thumbnailRepositoryFactor())
            {
                var result = AbstractTypeFactory <ThumbnailOptionSearchResult> .TryCreateInstance();

                var sortInfos = BuildSortExpression(criteria);
                var query     = BuildQuery(repository, criteria);

                result.TotalCount = await query.CountAsync();

                if (criteria.Take > 0)
                {
                    var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id)
                              .Select(x => x.Id)
                              .Skip(criteria.Skip).Take(criteria.Take)
                              .ToArrayAsync();

                    result.Results = (await _optionsService.GetByIdsAsync(ids)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList();
                }
                return(result);
            }
        }
Example #7
0
        public async Task <ActionResult <ThumbnailOptionSearchResult> > SearchThumbnailOption([FromBody] ThumbnailOptionSearchCriteria criteria)
        {
            var result = await _thumbnailOptionSearchService.SearchAsync(criteria);

            return(Ok(result));
        }
Example #8
0
        protected virtual IQueryable <ThumbnailOptionEntity> BuildQuery(IThumbnailRepository repository, ThumbnailOptionSearchCriteria criteria)
        {
            var query = repository.ThumbnailOptions;

            return(query);
        }