Exemple #1
0
        public GenericSearchResult <AverageProductRate> SearchAverageProductRate(
            AverageProductRateSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException($"{nameof(criteria)} must be set");
            }

            var retVal = new GenericSearchResult <AverageProductRate>();

            using (var repository = _repositoryFactory())
            {
                var query = repository.AverageProductRates;

                if (!criteria.ProductIds.IsNullOrEmpty())
                {
                    query = query.Where(x => criteria.ProductIds.Contains(x.ProductId));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[]
                    { new SortInfo {
                          SortColumn = "ProductId", SortDirection = SortDirection.Descending
                      } };
                }
                query = query.OrderBySortInfos(sortInfos);

                retVal.TotalCount = query.Count();

                var averageProductRateIds = query.Skip(criteria.Skip)
                                            .Take(criteria.Take)
                                            .Select(x => x.ProductId)
                                            .ToList();

                retVal.Results = _averageProductRateService.GetByProductIds(averageProductRateIds.ToArray())
                                 .OrderBy(x => averageProductRateIds.IndexOf(x.ProductId)).ToList();
                return(retVal);
            }
        }
Exemple #2
0
        public IHttpActionResult SearchAverageProductRate(AverageProductRateSearchCriteria criteria)
        {
            var result = _averageProductRateSearchService.SearchAverageProductRate(criteria);

            return(Ok(result));
        }