コード例 #1
0
        public GenericSearchResult <FulfillmentCenter> SearchCenters(FulfillmentCenterSearchCriteria criteria)
        {
            var result = new GenericSearchResult <FulfillmentCenter>();

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

                var query = repository.FulfillmentCenters;
                if (!string.IsNullOrEmpty(criteria.SearchPhrase))
                {
                    query = query.Where(x => x.Name.Contains(criteria.SearchPhrase));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Name"
                                        } };
                }

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

                result.TotalCount = query.Count();
                result.Results    = query.Skip(criteria.Skip)
                                    .Take(criteria.Take)
                                    .ToArray()
                                    .Select(x => x.ToModel(AbstractTypeFactory <FulfillmentCenter> .TryCreateInstance()))
                                    .ToList();
            }
            return(result);
        }
コード例 #2
0
        public IHttpActionResult SearchCustomerReviews([FromBody] CustomerReviewSearchCriteria criteria)

        {
            GenericSearchResult <CustomerReview> result = _customerReviewSearchService.SearchCustomerReviews(criteria);

            return(Ok(result));
        }
        // Mock. TODO: write implementation
        public virtual GenericSearchResult <domainModel.FulfillmentCenter> SearchFulfillmentCenters(FulfillmentCenterSearchCriteria criteria)
        {
            using (var repository = _repositoryFactory())
            {
                repository.DisableChangesTracking();

                var query = repository.FulfillmentCenters;

                // TODO

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <dataModel.FulfillmentCenter>(x => x.Name), SortDirection = SortDirection.Descending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos);

                var result = new GenericSearchResult <domainModel.FulfillmentCenter> {
                    TotalCount = query.Count()
                };
                var fulfillmentIds = query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArray();
                result.Results = GetFulfillmentCentersById(fulfillmentIds);
                return(result);
            }
        }
コード例 #4
0
        public async Task <GenericSearchResult <License> > SearchAsync(LicenseSearchCriteria criteria)
        {
            using (var repository = _licenseRepositoryFactory())
            {
                var query = repository.Licenses;

                if (criteria.Keyword != null)
                {
                    query = query.Where(x => x.CustomerName.Contains(criteria.Keyword));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <License>(x => x.CreatedDate), SortDirection = SortDirection.Descending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos);
                var arrayLicense = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();

                var retVal = new GenericSearchResult <License>
                {
                    TotalCount = await query.CountAsync(),
                    Results    = arrayLicense.Select(x => x.ToModel(AbstractTypeFactory <License> .TryCreateInstance())).ToArray()
                };
                return(retVal);
            }
        }
コード例 #5
0
        public GenericSearchResult <PropertyDictionaryValue> SearchPropertyDictionaryValues(PropertyDictionaryValueSearchCriteria criteria)
        {
            var result = new GenericSearchResult <PropertyDictionaryValue>();

            using (var repository = _repositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var query = repository.PropertyDictionaryValues;
                if (!string.IsNullOrEmpty(criteria.PropertyId))
                {
                    query = query.Where(x => x.PropertyId == criteria.PropertyId);
                }
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Value.Contains(criteria.Keyword) || x.Alias.Contains(criteria.Keyword));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Value"
                                        } };
                }
                query             = query.OrderBySortInfos(sortInfos);
                result.TotalCount = query.Count();
                result.Results    = query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.ToModel(AbstractTypeFactory <PropertyDictionaryValue> .TryCreateInstance())).ToList();
            }
            return(result);
        }
コード例 #6
0
        public async Task TestDataExport()
        {
            // Arrange
            var sitemapSearchCriteria = new SitemapSearchCriteria
            {
                Skip = 0,
                Take = int.MaxValue
            };
            var sitemapSearchResult = new GenericSearchResult <Sitemap>
            {
                TotalCount = TestSitemaps.Count,
                Results    = TestSitemaps
            };

            _sitemapService.Setup(service => service.SearchAsync(sitemapSearchCriteria))
            .ReturnsAsync(sitemapSearchResult);

            var sitemapItemSearchCriteria = new SitemapItemSearchCriteria
            {
                Skip = 0,
                Take = int.MaxValue
            };
            var sitemapItemsSearchResult = new GenericSearchResult <SitemapItem>
            {
                TotalCount = TestSitemapItems.Count,
                Results    = TestSitemapItems
            };

            _sitemapItemService.Setup(service => service.SearchAsync(sitemapItemSearchCriteria))
            .ReturnsAsync(sitemapItemsSearchResult);

            string expectedJson;

            using (var resourceStream = ReadEmbeddedResource("Resources.SerializedSitemapsData.json"))
                using (var textReader = new StreamReader(resourceStream))
                {
                    expectedJson = await textReader.ReadToEndAsync();
                }

            // Act
            string actualJson;

            using (var targetStream = new MemoryStream())
            {
                await _sitemapExportImport.DoExportAsync(targetStream, IgnoreProgressInfo, _cancellationToken.Object);

                var targetStreamContents = targetStream.ToArray();
                using (var copiedStream = new MemoryStream(targetStreamContents))
                    using (var textReader = new StreamReader(copiedStream))
                    {
                        actualJson = textReader.ReadToEnd();
                    }
            }

            // Assert
            var expectedJObject = JsonConvert.DeserializeObject <JObject>(expectedJson);
            var actualJObject   = JsonConvert.DeserializeObject <JObject>(actualJson);

            Assert.True(JToken.DeepEquals(expectedJObject, actualJObject));
        }
コード例 #7
0
        public async Task<GenericSearchResult<ObjectSettingEntry>> SearchSettingsAsync(SettingsSearchCriteria criteria)
        {
            var result = new GenericSearchResult<ObjectSettingEntry>();

            var query = _settingsManager.AllRegisteredSettings.AsQueryable();

            if (!string.IsNullOrEmpty(criteria.ModuleId))
            {
                query = query.Where(x => x.ModuleId == criteria.ModuleId);
            }

            var sortInfos = criteria.SortInfos;
            if (sortInfos.IsNullOrEmpty())
            {
                sortInfos = new[] { new SortInfo { SortColumn = "Name" } };
            }
            query = query.OrderBySortInfos(sortInfos);
            result.TotalCount = query.Count();
            var names = query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Name).ToList();

            var settings = await _settingsManager.GetObjectSettingsAsync(names.ToArray());
            result.Results = settings.OrderBy(x => names.IndexOf(x.Name))
                                       .ToList();
            return result;
        }
コード例 #8
0
        public virtual GenericSearchResult <CustomerOrder> SearchCustomerOrders(CustomerOrderSearchCriteria criteria)
        {
            using (var repository = RepositoryFactory())
            {
                repository.DisableChangesTracking();

                var query      = GetOrdersQuery(repository, criteria);
                var totalCount = query.Count();

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

                var orderIds = query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArray();
                var orders   = GetByIds(orderIds, criteria.ResponseGroup);

                var retVal = new GenericSearchResult <CustomerOrder>
                {
                    TotalCount = totalCount,
                    Results    = orders.AsQueryable().OrderBySortInfos(sortInfos).ToList()
                };

                return(retVal);
            }
        }
コード例 #9
0
        public virtual GenericSearchResult <coreModel.Promotion> SearchPromotions(PromotionSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <coreModel.Promotion>();

            using (var repository = _repositoryFactory())
            {
                var query = GetPromotionsQuery(repository, criteria);

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <coreModel.Promotion>(x => x.Priority), SortDirection = SortDirection.Descending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

                retVal.TotalCount = query.Count();

                var ids = query.Select(x => x.Id)
                          .Skip(criteria.Skip)
                          .Take(criteria.Take)
                          .ToArray();

                retVal.Results = _promotionSrevice.GetPromotionsByIds(ids)
                                 .OrderBy(p => Array.IndexOf(ids, p.Id))
                                 .ToList();
            }
            return(retVal);
        }
        public IHttpActionResult DynamicContentItemsEntriesSearch(DynamicContentItemSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <webModel.DynamicContentListEntry>();

            retVal.Results = new List <webModel.DynamicContentListEntry>();

            var foldersSearchResult = _dynamicConentSearchService.SearchFolders(new DynamicContentFolderSearchCriteria {
                FolderId = criteria.FolderId, Keyword = criteria.Keyword, Take = criteria.Take, Skip = criteria.Skip, Sort = criteria.Sort
            });
            var folderSkip = Math.Min(foldersSearchResult.TotalCount, criteria.Skip);
            var folderTake = Math.Min(criteria.Take, Math.Max(0, foldersSearchResult.TotalCount - criteria.Skip));
            var folders    = foldersSearchResult.Results.Skip(folderSkip).Take(folderTake).Select(x => x.ToWebModel());

            retVal.TotalCount += foldersSearchResult.TotalCount;
            retVal.Results.AddRange(folders);

            criteria.Skip = criteria.Skip - folderSkip;
            criteria.Take = criteria.Take - folderTake;

            var itemsSearchResult = _dynamicConentSearchService.SearchContentItems(criteria);

            retVal.TotalCount += itemsSearchResult.TotalCount;
            retVal.Results.AddRange(itemsSearchResult.Results.Select(x => x.ToWebModel()));

            return(Ok(retVal));
        }
コード例 #11
0
        public GenericSearchResult <ProductAssociation> SearchProductAssociations(ProductAssociationSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            if (criteria.ObjectIds.IsNullOrEmpty())
            {
                return(new GenericSearchResult <ProductAssociation>());
            }

            using (var repository = _catalogRepositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var result = new GenericSearchResult <ProductAssociation>();

                var dbResult = repository.SearchAssociations(criteria);

                result.TotalCount = dbResult.TotalCount;
                result.Results    = dbResult.Results.Select(x => x.ToModel(AbstractTypeFactory <ProductAssociation> .TryCreateInstance())).ToList();
                return(result);
            }
        }
コード例 #12
0
        public GenericSearchResult <PaymentPlan> SearchPlans(PaymentPlanSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <PaymentPlan>();

            using (var repository = _subscriptionRepositoryFactory())
            {
                var query = repository.PaymentPlans;

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

                retVal.TotalCount = query.Count();

                var paymentPlanIds = query.Skip(criteria.Skip)
                                     .Take(criteria.Take)
                                     .ToArray()
                                     .Select(x => x.Id)
                                     .ToArray();

                //Load subscriptions with preserving sorting order
                retVal.Results = GetByIds(paymentPlanIds, criteria.ResponseGroup).OrderBy(x => Array.IndexOf(paymentPlanIds, x.Id)).ToArray();
                return(retVal);
            }
        }
コード例 #13
0
        public async Task <GenericSearchResult <DynamicContentFolder> > SearchFoldersAsync(DynamicContentFolderSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchFoldersAsync", criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(DynamicContentFolderCacheRegion.CreateChangeToken());
                var retVal = new GenericSearchResult <DynamicContentFolder>();
                using (var repository = _repositoryFactory())
                {
                    var query = repository.Folders.Where(x => x.ParentFolderId == criteria.FolderId);
                    if (!string.IsNullOrEmpty(criteria.Keyword))
                    {
                        query = query.Where(q => q.Name.Contains(criteria.Keyword));
                    }
                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[] { new SortInfo {
                                                SortColumn = ReflectionUtility.GetPropertyName <DynamicContentFolder>(x => x.Name), SortDirection = SortDirection.Ascending
                                            } };
                    }

                    query = query.OrderBySortInfos(sortInfos);
                    retVal.TotalCount = await query.CountAsync();

                    if (criteria.Take > 0)
                    {
                        var folderIds = await query.Select(x => x.Id).ToArrayAsync();
                        retVal.Results = await _dynamicContentService.GetFoldersByIdsAsync(folderIds);
                    }
                }
                return retVal;
            }));
        }
コード例 #14
0
        public virtual GenericSearchResult <PromotionUsage> SearchUsages(PromotionUsageSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            using (var repository = _repositoryFactory())
            {
                var query = GetPromotionUsageQuery(repository, criteria);

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <PromotionUsage>(x => x.ModifiedDate), SortDirection = SortDirection.Descending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos);

                var searchResult = new GenericSearchResult <PromotionUsage> {
                    TotalCount = query.Count()
                };

                var coupons = query.Skip(criteria.Skip).Take(criteria.Take).ToList();
                searchResult.Results = coupons.Select(x => x.ToModel(AbstractTypeFactory <PromotionUsage> .TryCreateInstance())).ToList();

                return(searchResult);
            }
        }
        public async Task <ActionResult <GenericSearchResult <coreModel.DynamicContentListEntry> > > DynamicContentItemsEntriesSearch([FromBody] coreModel.DynamicContentItemSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <coreModel.DynamicContentListEntry>
            {
                Results = new List <coreModel.DynamicContentListEntry>()
            };

            var foldersSearchResult = await _dynamicConentSearchService.SearchFoldersAsync(new coreModel.DynamicContentFolderSearchCriteria {
                FolderId = criteria.FolderId, Keyword = criteria.Keyword, Take = criteria.Take, Skip = criteria.Skip, Sort = criteria.Sort
            });

            var folderSkip = Math.Min(foldersSearchResult.TotalCount, criteria.Skip);
            var folderTake = Math.Min(criteria.Take, Math.Max(0, foldersSearchResult.TotalCount - criteria.Skip));

            retVal.TotalCount += foldersSearchResult.TotalCount;
            retVal.Results.AddRange(foldersSearchResult.Results.Skip(folderSkip).Take(folderTake));

            criteria.Skip = criteria.Skip - folderSkip;
            criteria.Take = criteria.Take - folderTake;

            var itemsSearchResult = await _dynamicConentSearchService.SearchContentItemsAsync(criteria);

            retVal.TotalCount += itemsSearchResult.TotalCount;
            retVal.Results.AddRange(itemsSearchResult.Results);

            return(Ok(retVal));
        }
コード例 #16
0
        public async Task <GenericSearchResult <ThumbnailTask> > SearchAsync(ThumbnailTaskSearchCriteria criteria)
        {
            using (var repository = _thumbnailRepositoryFactory())
            {
                var query = GetTasksQuery(repository, criteria);

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

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

                var thumbnailTasks = await repository.GetThumbnailTasksByIdsAsync(ids);

                var results = thumbnailTasks.Select(t => t.ToModel(AbstractTypeFactory <ThumbnailTask> .TryCreateInstance())).ToArray();

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

                return(retVal);
            }
        }
コード例 #17
0
        public virtual async Task <GenericSearchResult <InventoryInfo> > SearchInventoriesAsync(InventorySearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchInventoriesAsync", criteria.GetCacheKey());

            return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(InventorySearchCacheRegion.CreateChangeToken());
                var result = new GenericSearchResult <InventoryInfo>();
                using (var repository = RepositoryFactory())
                {
                    repository.DisableChangesTracking();

                    var sortInfos = GetSortInfos(criteria);
                    var query = GetQuery(repository, criteria, sortInfos);

                    result.TotalCount = await query.CountAsync();
                    if (criteria.Take > 0)
                    {
                        var inventoryIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                        result.Results = (await InventoryService.GetByIdsAsync(inventoryIds, criteria.ResponseGroup)).AsQueryable().OrderBySortInfos(sortInfos).ToArray();
                    }
                }
                return result;
            }));
        }
コード例 #18
0
        public GenericSearchResult <ListEntryBase> Search(CatalogListEntrySearchCriteria criteria)
        {
            var result = new GenericSearchResult <ListEntryBase>();

            using (var repository = _catalogRepositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var query = repository.Categories.Where(cat => cat.CatalogId == criteria.CatalogId && cat.ParentCategoryId == criteria.CategoryId).Select(cat => new { cat.Id, cat.Name, cat.Code })
                            .Union(repository.Items.Where(item => item.CatalogId == criteria.CatalogId && item.CategoryId == criteria.CategoryId).Select(item => new { item.Id, item.Name, item.Code }));

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Name"
                                        } };
                }
                query             = query.OrderBySortInfos(sortInfos);
                result.TotalCount = query.Count();
                var ids = query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToList();
                var productsListEntries   = _itemService.GetByIds(ids, (ItemResponseGroup.ItemInfo | ItemResponseGroup.ItemAssets | ItemResponseGroup.Outlines).ToString()).Select(x => AbstractTypeFactory <ProductListEntry> .TryCreateInstance().FromModel(x));
                var categoriesListEntries = _categoryService.GetByIds(ids, (CategoryResponseGroup.Info | CategoryResponseGroup.WithImages | CategoryResponseGroup.WithOutlines).ToString()).Select(x => AbstractTypeFactory <CategoryListEntry> .TryCreateInstance().FromModel(x));;
                result.Results = productsListEntries.Concat(categoriesListEntries).OrderBy(x => ids.IndexOf(x.Id)).ToList();
            }
            return(result);
        }
コード例 #19
0
        public virtual async Task <GenericSearchResult <Store> > SearchStoresAsync(StoreSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchStoresAsync", criteria.GetCacheKey());

            return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(StoreSearchCacheRegion.CreateChangeToken());
                var result = new GenericSearchResult <Store>();
                using (var repository = RepositoryFactory())
                {
                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[]
                        {
                            new SortInfo
                            {
                                SortColumn = "Name"
                            }
                        };
                    }

                    var query = GetStoresQuery(repository, criteria, sortInfos);

                    result.TotalCount = await query.CountAsync();
                    if (criteria.Take > 0)
                    {
                        var storeIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                        result.Results = (await StoreService.GetByIdsAsync(storeIds)).AsQueryable().OrderBySortInfos(sortInfos).ToList();
                    }
                }
                return result;
            }));
        }
コード例 #20
0
        public GenericSearchResult <CustomerReviewRating> GetRatings(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }

            using (var repository = _repositoryFactory())
            {
                var ratings = repository.GetByIds(new string[] { id })
                              .FirstOrDefault()
                              ?.Ratings
                              .Select(r => r.ToModel(new CustomerReviewRating()))
                              .ToList();

                var result = new GenericSearchResult <CustomerReviewRating>();
                if (ratings != null)
                {
                    result.TotalCount = ratings.Count;
                    result.Results    = ratings;
                }

                return(result);
            }
        }
コード例 #21
0
        public virtual async Task <GenericSearchResult <Promotion> > SearchPromotionsAsync(PromotionSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchPromotionsAsync", criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(PromotionCacheRegion.CreateChangeToken());
                var retVal = new GenericSearchResult <Promotion>();
                using (var repository = _repositoryFactory())
                {
                    var query = GetPromotionsQuery(repository, criteria);

                    var sortInfos = criteria.SortInfos;
                    if (sortInfos.IsNullOrEmpty())
                    {
                        sortInfos = new[] { new SortInfo {
                                                SortColumn = ReflectionUtility.GetPropertyName <Promotion>(x => x.Priority), SortDirection = SortDirection.Descending
                                            } };
                    }
                    query = query.OrderBySortInfos(sortInfos);

                    retVal.TotalCount = await query.CountAsync();

                    if (criteria.Take > 0)
                    {
                        var ids = await query.Select(x => x.Id)
                                  .Skip(criteria.Skip)
                                  .Take(criteria.Take).ToArrayAsync();
                        var promotions = await _promotionService.GetPromotionsByIdsAsync(ids);
                        retVal.Results = promotions.OrderBy(p => ids.ToList().IndexOf(p.Id)).ToList();
                    }
                }
                return retVal;
            }));
        }
コード例 #22
0
        public GenericSearchResult <coreModel.DynamicContentItem> SearchContentItems(DynamicContentItemSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <coreModel.DynamicContentItem>();

            using (var repository = _repositoryFactory())
            {
                var query = repository.Items;
                if (!string.IsNullOrEmpty(criteria.FolderId))
                {
                    query = query.Where(x => x.FolderId == criteria.FolderId);
                }
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(q => q.Name.Contains(criteria.Keyword));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = ReflectionUtility.GetPropertyName <coreModel.DynamicContentItem>(x => x.Name), SortDirection = SortDirection.Ascending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos);

                retVal.TotalCount = query.Count();

                var ids = query.Select(x => x.Id)
                          .Skip(criteria.Skip)
                          .Take(criteria.Take).ToArray();
                retVal.Results = _dynamicContentService.GetContentItemsByIds(ids);
            }
            return(retVal);
        }
コード例 #23
0
        public virtual async Task <GenericSearchResult <ThumbnailTask> > SearchAsync(ThumbnailTaskSearchCriteria criteria)
        {
            var result = new GenericSearchResult <ThumbnailTask>();

            using (var repository = ThumbnailRepositoryFactory())
            {
                var query = GetTasksQuery(repository, criteria);

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

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

                    result.Results = (await ThumbnailTaskService.GetByIdsAsync(ids)).AsQueryable().OrderBySortInfos(sortInfos).ToArray();
                }
            }
            return(result);
        }
コード例 #24
0
        public virtual async Task <GenericSearchResult <FulfillmentCenter> > SearchCentersAsync(FulfillmentCenterSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), "SearchCentersAsync", criteria.GetCacheKey());

            return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(FulfillmentCenterCacheRegion.CreateChangeToken());
                var result = new GenericSearchResult <FulfillmentCenter>();
                using (var repository = RepositoryFactory())
                {
                    repository.DisableChangesTracking();

                    var sortInfos = GetSortInfos(criteria);
                    var query = GetFulfillmentCenterQuery(repository, criteria, sortInfos);

                    result.TotalCount = await query.CountAsync();

                    var fulfillmentCenterEntities = new FulfillmentCenterEntity[0];
                    if (criteria.Take > 0)
                    {
                        fulfillmentCenterEntities = await query.Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                    }

                    result.Results = fulfillmentCenterEntities
                                     .Select(x => x.ToModel(AbstractTypeFactory <FulfillmentCenter> .TryCreateInstance()))
                                     .ToList();
                }
                return result;
            }));
        }
コード例 #25
0
        public virtual async Task <GenericSearchResult <Subscription> > SearchSubscriptionsAsync(SubscriptionSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchSubscriptionsAsync), criteria.GetCacheKey());

            return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry =>
            {
                cacheEntry.AddExpirationToken(SubscriptionSearchCacheRegion.CreateChangeToken());

                var retVal = new GenericSearchResult <Subscription>();
                using (var repository = SubscriptionRepositoryFactory())
                {
                    repository.DisableChangesTracking();

                    var query = await GetSubscriptionsQueryForCriteria(repository, criteria);

                    retVal.TotalCount = await query.CountAsync();

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

                        //Load subscriptions with preserving sorting order
                        var unorderedResults = await GetByIdsAsync(subscriptionsIds, criteria.ResponseGroup);
                        retVal.Results = unorderedResults.OrderBy(x => Array.IndexOf(subscriptionsIds, x.Id)).ToArray();
                    }

                    return retVal;
                }
            }));
        }
コード例 #26
0
        public GenericSearchResult <Property> SearchProperties(PropertySearchCriteria criteria)
        {
            var result = new GenericSearchResult <Property>();

            using (var repository = _repositoryFactory())
            {
                //Optimize performance and CPU usage
                repository.DisableChangesTracking();

                var query = repository.Properties;
                if (!string.IsNullOrEmpty(criteria.CatalogId))
                {
                    query = query.Where(x => x.CatalogId == criteria.CatalogId);
                }
                if (!string.IsNullOrEmpty(criteria.Keyword))
                {
                    query = query.Where(x => x.Name.Contains(criteria.Keyword));
                }

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "Name"
                                        } };
                }
                query             = query.OrderBySortInfos(sortInfos);
                result.TotalCount = query.Count();
                var ids = query.Skip(criteria.Skip).Take(criteria.Take).Select(x => x.Id).ToList();

                var properties = _propertyService.GetByIds(ids);
                result.Results = properties.OrderBy(x => ids.IndexOf(x.Id)).ToList();
            }
            return(result);
        }
コード例 #27
0
        public async Task <GenericSearchResult <Role> > SearchRolesAsync(RoleSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }
            if (!_roleManager.SupportsQueryableRoles)
            {
                throw new NotSupportedException();
            }
            var result = new GenericSearchResult <Role>();
            var query  = _roleManager.Roles;

            if (criteria.Keyword != null)
            {
                query = query.Where(r => r.Name.Contains(criteria.Keyword));
            }
            result.TotalCount = await query.CountAsync();

            var sortInfos = criteria.SortInfos;

            if (sortInfos.IsNullOrEmpty())
            {
                sortInfos = new[] { new SortInfo {
                                        SortColumn = ReflectionUtility.GetPropertyName <Role>(x => x.Name), SortDirection = SortDirection.Descending
                                    } };
            }
            result.Results = await query.OrderBySortInfos(sortInfos).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();

            return(result);
        }
コード例 #28
0
        public GenericSearchResult <ShoppingCart> Search(ShoppingCartSearchCriteria criteria)
        {
            var retVal = new GenericSearchResult <ShoppingCart>();

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

                if (!string.IsNullOrEmpty(criteria.Status))
                {
                    query = query.Where(x => x.Status == criteria.Status);
                }

                if (!string.IsNullOrEmpty(criteria.Name))
                {
                    query = query.Where(x => x.Name == criteria.Name);
                }

                if (!string.IsNullOrEmpty(criteria.CustomerId))
                {
                    query = query.Where(x => x.CustomerId == criteria.CustomerId);
                }

                if (!string.IsNullOrEmpty(criteria.StoreId))
                {
                    query = query.Where(x => criteria.StoreId == x.StoreId);
                }

                if (!string.IsNullOrEmpty(criteria.Currency))
                {
                    query = query.Where(x => x.Currency == criteria.Currency);
                }

                if (!string.IsNullOrEmpty(criteria.Type))
                {
                    query = query.Where(x => x.Type == criteria.Type);
                }

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

                query = query.OrderBySortInfos(sortInfos);

                retVal.TotalCount = query.Count();

                var cartIds = query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArray();
                var carts   = GetByIds(cartIds);
                retVal.Results = carts.AsQueryable().OrderBySortInfos(sortInfos).ToList();

                return(retVal);
            }
        }
        public IHttpActionResult DynamicContentPlacesSearch(DynamicContentPlaceSearchCriteria criteria)
        {
            var retVal             = new GenericSearchResult <webModel.DynamicContentPlace>();
            var placesSearchResult = _dynamicConentSearchService.SearchContentPlaces(criteria);

            retVal.TotalCount = placesSearchResult.TotalCount;
            retVal.Results    = placesSearchResult.Results.Select(x => x.ToWebModel()).ToList();
            return(Ok(retVal));
        }
コード例 #30
0
        public virtual async Task <GenericSearchResult <Sitemap> > SearchAsync(SitemapSearchCriteria criteria)
        {
            if (criteria == null)
            {
                throw new ArgumentNullException(nameof(criteria));
            }

            var cacheKey = CacheKey.With(GetType(), nameof(SearchAsync), criteria.GetCacheKey());

            return(await PlatformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry =>
            {
                cacheEntry.AddExpirationToken(SitemapSearchCacheRegion.CreateChangeToken());

                using (var repository = RepositoryFactory())
                {
                    var result = new GenericSearchResult <Sitemap>();

                    var query = repository.Sitemaps;

                    if (!string.IsNullOrEmpty(criteria.StoreId))
                    {
                        query = query.Where(s => s.StoreId == criteria.StoreId);
                    }

                    if (!string.IsNullOrEmpty(criteria.Location))
                    {
                        query = query.Where(s => s.Filename == criteria.Location);
                    }

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

                    query = query.OrderBySortInfos(sortInfos);

                    result.TotalCount = await query.CountAsync();

                    if (criteria.Take > 0)
                    {
                        var sitemapIds = await query.Select(x => x.Id).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();
                        result.Results = (await GetByIdsAsync(sitemapIds, criteria.ResponseGroup)).AsQueryable().OrderBySortInfos(sortInfos).ToArray();
                    }

                    return result;
                }
            }));
        }