Пример #1
0
        private PricingSearchResult <webModel.ProductPrice> SearchProductPricesImpl(PricesSearchCriteria criteria)
        {
            if (criteria == null)
            {
                criteria = new PricesSearchCriteria();
            }
            var result = _pricingSearchService.SearchPrices(criteria);
            var retVal = new PricingSearchResult <webModel.ProductPrice>
            {
                TotalCount = result.TotalCount,
                Results    = new List <webModel.ProductPrice>()
            };

            var products = _itemService.GetByIds(result.Results.Select(x => x.ProductId).Distinct().ToArray(), Domain.Catalog.Model.ItemResponseGroup.ItemInfo);

            foreach (var productPricesGroup in result.Results.GroupBy(x => x.ProductId))
            {
                var productPrice = new webModel.ProductPrice
                {
                    ProductId = productPricesGroup.Key,
                    Prices    = productPricesGroup.ToList()
                };
                var product = products.FirstOrDefault(x => x.Id == productPricesGroup.Key);
                if (product != null)
                {
                    productPrice.Product = product.ToWebModel(_blobUrlResolver);
                }
                retVal.Results.Add(productPrice);
            }
            return(retVal);
        }
Пример #2
0
        public virtual PricingSearchResult <coreModel.Pricelist> SearchPricelists(PricelistSearchCriteria criteria)
        {
            var result = new PricingSearchResult <coreModel.Pricelist>();

            using (var repository = _repositoryFactory())
            {
                repository.DisableChangesTracking();

                var query = GetPricelistsQuery(repository, criteria);

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <coreModel.Pricelist>(x => x.Name)
                                        } };
                }

                query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

                result.TotalCount = query.Count();
                query             = query.Skip(criteria.Skip).Take(criteria.Take);

                var pricelistsIds = query.Select(x => x.Id).ToList();
                result.Results = _pricingService.GetPricelistsById(pricelistsIds.ToArray())
                                 .OrderBy(x => pricelistsIds.IndexOf(x.Id)).ToList();
            }
            return(result);
        }
Пример #3
0
        public virtual PricingSearchResult <coreModel.Pricelist> SearchPricelists(PricelistSearchCriteria criteria)
        {
            var retVal = new PricingSearchResult <coreModel.Pricelist>();

            using (var repository = _repositoryFactory())
            {
                var query = repository.Pricelists;
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Name.Contains(criteria.Keyword) || x.Description.Contains(criteria.Keyword));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <coreModel.Pricelist>(x => x.Name)
                                        } };
                }

                query = query.OrderBySortInfos(sortInfos);

                retVal.TotalCount = query.Count();
                query             = query.Skip(criteria.Skip).Take(criteria.Take);

                var pricelistsIds = query.Select(x => x.Id).ToList();
                retVal.Results = _pricingService.GetPricelistsById(pricelistsIds.ToArray())
                                 .OrderBy(x => pricelistsIds.IndexOf(x.Id)).ToList();
            }
            return(retVal);
        }
Пример #4
0
        public virtual PricingSearchResult <coreModel.Price> SearchPrices(PricesSearchCriteria criteria)
        {
            var result = new PricingSearchResult <coreModel.Price>();

            ICollection <CatalogProduct> products;

            using (var repository = _repositoryFactory())
            {
                repository.DisableChangesTracking();

                var query = GetPricesQuery(repository, criteria, out products);

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <coreModel.Price>(x => x.List)
                                        } };
                }
                //Try to replace sorting columns names
                TryTransformSortingInfoColumnNames(_pricesSortingAliases, sortInfos);

                query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

                if (criteria.GroupByProducts)
                {
                    var groupedQuery = query.GroupBy(x => x.ProductId).OrderBy(x => 1);
                    result.TotalCount = groupedQuery.Count();
                    query             = groupedQuery.Skip(criteria.Skip).Take(criteria.Take).SelectMany(x => x);
                }
                else
                {
                    result.TotalCount = query.Count();
                    query             = query.Skip(criteria.Skip).Take(criteria.Take);
                }

                var pricesIds = query.Select(x => x.Id).ToList();
                result.Results = _pricingService.GetPricesById(pricesIds.ToArray())
                                 .OrderBy(x => pricesIds.IndexOf(x.Id))
                                 .ToList();
            }

            return(result);
        }
Пример #5
0
        public virtual PricingSearchResult <coreModel.Price> SearchPrices(PricesSearchCriteria criteria)
        {
            var retVal = new PricingSearchResult <coreModel.Price>();
            ICollection <CatalogProduct> products = new List <CatalogProduct>();

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

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

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

                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    var catalogSearchResult = _catalogSearchService.Search(new Domain.Catalog.Model.SearchCriteria {
                        Keyword = criteria.Keyword, Skip = criteria.Skip, Take = criteria.Take, Sort = criteria.Sort.Replace("product.", string.Empty), ResponseGroup = Domain.Catalog.Model.SearchResponseGroup.WithProducts
                    });
                    var productIds = catalogSearchResult.Products.Select(x => x.Id).ToArray();
                    query = query.Where(x => productIds.Contains(x.ProductId));
                    //preserve resulting products for future assignment to prices
                    products = catalogSearchResult.Products;
                }

                if (criteria.ModifiedSince.HasValue)
                {
                    query = query.Where(x => x.ModifiedDate >= criteria.ModifiedSince);
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <coreModel.Price>(x => x.List)
                                        } };
                }
                //Try to replace sorting columns names
                TryTransformSortingInfoColumnNames(_pricesSortingAliases, sortInfos);


                query = query.OrderBySortInfos(sortInfos);

                if (criteria.GroupByProducts)
                {
                    var groupedQuery = query.GroupBy(x => x.ProductId).OrderBy(x => 1);
                    retVal.TotalCount = groupedQuery.Count();
                    query             = groupedQuery.Skip(criteria.Skip).Take(criteria.Take).SelectMany(x => x);
                }
                else
                {
                    retVal.TotalCount = query.Count();
                    query             = query.Skip(criteria.Skip).Take(criteria.Take);
                }

                var pricesIds = query.Select(x => x.Id).ToList();
                retVal.Results = _pricingService.GetPricesById(pricesIds.ToArray())
                                 .OrderBy(x => pricesIds.IndexOf(x.Id))
                                 .ToList();
            }
            return(retVal);
        }