public async Task <GenericSearchResult <AssetEntry> > SearchAssetEntriesAsync(AssetEntrySearchCriteria criteria) { criteria = criteria ?? AbstractTypeFactory <AssetEntrySearchCriteria> .TryCreateInstance(); using (var repository = _platformRepository()) { var query = repository.AssetEntries; if (!string.IsNullOrEmpty(criteria.SearchPhrase)) { query = query.Where(x => x.Name.Contains(criteria.SearchPhrase) || x.RelativeUrl.Contains(criteria.SearchPhrase)); } if (!string.IsNullOrEmpty(criteria.LanguageCode)) { query = query.Where(x => x.LanguageCode == criteria.LanguageCode); } if (!string.IsNullOrEmpty(criteria.Group)) { query = query.Where(x => x.Group == criteria.Group); } if (!criteria.Tenants.IsNullOrEmpty()) { var tenants = criteria.Tenants.Where(x => x.IsValid).ToArray(); if (tenants.Any()) { var tenantsStrings = tenants.Select(x => x.ToString()); query = query.Where(x => tenantsStrings.Contains(x.TenantId + "_" + x.TenantType)); } } var result = new GenericSearchResult <AssetEntry>() { TotalCount = await query.CountAsync() }; var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "CreatedDate", SortDirection = SortDirection.Descending } }; } query = query.OrderBySortInfos(sortInfos); var ids = await query .Skip(criteria.Skip) .Take(criteria.Take) .Select(x => x.Id) .ToListAsync(); var asetsResult = await repository.GetAssetsByIdsAsync(ids); result.Results = asetsResult .Select(x => x.ToModel(AbstractTypeFactory <AssetEntry> .TryCreateInstance(), _blobUrlResolver)) .OrderBy(x => ids.IndexOf(x.Id)) .ToList(); return(result); } }
public AssetEntrySearchResult SearchAssetEntries(AssetEntrySearchCriteria criteria) { var cacheKey = $"Search:{criteria?.GetHashCode()}"; return(_cacheManager.Get(cacheKey, nameof(AssetEntry), () => { criteria = criteria ?? new AssetEntrySearchCriteria(); using (var repository = _platformRepository()) { var query = repository.AssetEntries; if (!string.IsNullOrEmpty(criteria.SearchPhrase)) { query = query.Where(x => x.Name.Contains(criteria.SearchPhrase) || x.RelativeUrl.Contains(criteria.SearchPhrase)); } if (!string.IsNullOrEmpty(criteria.LanguageCode)) { query = query.Where(x => x.LanguageCode == criteria.LanguageCode); } if (!string.IsNullOrEmpty(criteria.Group)) { query = query.Where(x => x.Group == criteria.Group); } if (!criteria.Tenants.IsNullOrEmpty()) { var tenants = criteria.Tenants.Where(x => x.IsValid).ToArray(); if (tenants.Any()) { var tenantsStrings = tenants.Select(x => x.ToString()); query = query.Where(x => tenantsStrings.Contains(x.TenantId + "_" + x.TenantType)); } } var result = new AssetEntrySearchResult { TotalCount = query.Count() }; var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = "CreatedDate", SortDirection = SortDirection.Descending } }; } query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id); var ids = query .Skip(criteria.Skip) .Take(criteria.Take) .Select(x => x.Id).ToList(); result.Results = repository.GetAssetsByIds(ids) .Select(x => x.ToModel(AbstractTypeFactory <AssetEntry> .TryCreateInstance(), _blobUrlResolver)) .OrderBy(x => ids.IndexOf(x.Id)) .ToList(); return result; } })); }
public async Task <ActionResult <AssetEntrySearchResult> > Search([FromBody] AssetEntrySearchCriteria criteria) { var result = await _assetSearchService.SearchAssetEntriesAsync(criteria); return(Ok(result)); }
// [CheckPermission(Permission = PredefinedPermissions.AssetAccess)] public IHttpActionResult Search(AssetEntrySearchCriteria criteria) { var result = _assetSearchService.SearchAssetEntries(criteria); return(Ok(result)); }