public virtual async Task <PricelistSearchResult> SearchPricelistsAsync(PricelistSearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), nameof(SearchPricelistsAsync), criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry => { cacheEntry.AddExpirationToken(PricingSearchCacheRegion.CreateChangeToken()); var result = AbstractTypeFactory <PricelistSearchResult> .TryCreateInstance(); using (var repository = _repositoryFactory()) { var query = BuildQuery(repository, criteria); var sortInfos = BuildSortExpression(criteria); result.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { var pricelistIds = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id) .Select(x => x.Id) .Skip(criteria.Skip).Take(criteria.Take) .AsNoTracking() .ToArrayAsync(); var unorderedResults = await _pricingService.GetPricelistsByIdAsync(pricelistIds); result.Results = unorderedResults.OrderBy(x => Array.IndexOf(pricelistIds, x.Id)).ToList(); } } return result; })); }
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); }
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); }
public IHttpActionResult SearchPricelists([FromUri] PricelistSearchCriteria criteria) { if (criteria == null) { criteria = new PricelistSearchCriteria(); } var result = _pricingSearchService.SearchPricelists(criteria); return(Ok(result)); }
public async Task <IActionResult> SearchPricelists(PricelistSearchCriteria criteria) { if (criteria == null) { criteria = new PricelistSearchCriteria(); } var result = await _pricingSearchService.SearchPricelistsAsync(criteria); return(Ok(result)); }
public async Task <IHttpActionResult> SearchPricelistsAsync(string keyword, int skip, int take, bool isAdmin, string isUserName, string selectedVendorId) { var criteria = new PricelistSearchCriteria(); criteria.Keyword = keyword; criteria.Skip = skip; criteria.Take = take; var result = await _pricingSearchService.SearchPricelistsAsync(criteria, isAdmin, isUserName, selectedVendorId); return(Ok(result)); }
protected virtual IList <SortInfo> BuildSortExpression(PricelistSearchCriteria criteria) { var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = nameof(PricelistEntity.Name) } }; } return(sortInfos); }
public virtual async Task <PricelistSearchResult> SearchPricelistsAsync(PricelistSearchCriteria criteria, bool isAdmin, string isUserName, string selectedVendorId) { var result = AbstractTypeFactory <PricelistSearchResult> .TryCreateInstance(); loginUserSelectedVendor = selectedVendorId; using (var repository = new PricingModuleCoreContext()) { var query = BuildQuery(repository, criteria); if (criteria.Take > 0) { var pricelistIds = await query.Select(x => x.Id) .ToArrayAsync(); var unorderedResults = _pricingService.GetPricelistsByIdAsync(pricelistIds); if (!isAdmin) { loginUserAssignedVendor = GetUserTypePermission(isUserName); string[] scopeIds = loginUserAssignedVendor.Split(','); var resultList = unorderedResults.Where(c => scopeIds.Contains(c.Vendors)); var priceList = resultList.Where(x => x.Vendors == selectedVendorId); result.Results = priceList.ToList(); return(result); } else { loginUserAssignedVendor = null; if (selectedVendorId != "null") { var priceList = unorderedResults.OrderBy(x => Array.IndexOf(pricelistIds, x.Id)).ToList(); var priceListforSelectedVendor = priceList.Where(x => x.Vendors == selectedVendorId); result.Results = priceListforSelectedVendor.ToList(); //result.Results = r.ToList(); return(result); } else { loginUserSelectedVendor = null; result.Results = unorderedResults.OrderBy(x => Array.IndexOf(pricelistIds, x.Id)).ToList(); return(result); } } } } return(result); }
public virtual async Task <PricelistSearchResult> SearchPricelistsAsync(PricelistSearchCriteria criteria) { var cacheKey = CacheKey.With(GetType(), nameof(SearchPricelistsAsync), criteria.GetCacheKey()); return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async cacheEntry => { cacheEntry.AddExpirationToken(PricingSearchCacheRegion.CreateChangeToken()); var retVal = AbstractTypeFactory <PricelistSearchResult> .TryCreateInstance(); 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 <Pricelist>(x => x.Name) } }; } query = query.OrderBySortInfos(sortInfos); retVal.TotalCount = await query.CountAsync(); if (criteria.Take > 0) { query = query.Skip(criteria.Skip).Take(criteria.Take); var pricelistsIds = await query.Select(x => x.Id).ToListAsync(); retVal.Results = (await _pricingService.GetPricelistsByIdAsync(pricelistsIds.ToArray())) .OrderBy(x => pricelistsIds.IndexOf(x.Id)).ToList(); } } return retVal; })); }
protected virtual IQueryable <PricelistEntity> BuildQuery(PricingModuleCoreContext repository, PricelistSearchCriteria criteria) { var query = repository.Pricelists; if (!string.IsNullOrEmpty(criteria.Keyword) && criteria.Keyword != "null") { query = query.Where(x => x.Name.Contains(criteria.Keyword) || x.Description.Contains(criteria.Keyword)); } if (!criteria.Currencies.IsNullOrEmpty()) { query = query.Where(x => criteria.Currencies.Contains(x.Currency)); } return(query); }