public PricelistAssignment[] GetPricelistAssignmentsById(string[] ids)
        {
            var cacheKey = GetCacheKey("IPricingService.GetPricelistAssignmentsById", string.Join(", ", ids));
            var retVal   = _cacheManager.Get(cacheKey, RegionName, () => _pricingService.GetPricelistAssignmentsById(ids));

            return(retVal);
        }
Exemplo n.º 2
0
        public virtual PricingSearchResult <coreModel.PricelistAssignment> SearchPricelistAssignments(PricelistAssignmentsSearchCriteria criteria)
        {
            var result = new PricingSearchResult <coreModel.PricelistAssignment>();

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

                var query = GetPricelistAssignmentsQuery(repository, criteria);

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

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

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

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

            return(result);
        }
        public virtual PricingSearchResult <coreModel.PricelistAssignment> SearchPricelistAssignments(PricelistAssignmentsSearchCriteria criteria)
        {
            var retVal = new PricingSearchResult <coreModel.PricelistAssignment>();

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

                var query = repository.PricelistAssignments;

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

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

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

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

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

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

                var pricelistAssignmentsIds = query.Select(x => x.Id).ToList();
                retVal.Results = _pricingService.GetPricelistAssignmentsById(pricelistAssignmentsIds.ToArray())
                                 .OrderBy(x => pricelistAssignmentsIds.IndexOf(x.Id))
                                 .ToList();
            }
            return(retVal);
        }
        protected override ExportableSearchResult FetchData(PricelistAssignmentsSearchCriteria searchCriteria)
        {
            PricelistAssignment[] result;
            int totalCount;

            if (searchCriteria.ObjectIds.Any(x => !string.IsNullOrWhiteSpace(x)))
            {
                result     = _pricingService.GetPricelistAssignmentsById(Enumerable.ToArray(searchCriteria.ObjectIds));
                totalCount = result.Length;
            }
            else
            {
                var pricelistAssignmentSearchResult = _searchService.SearchPricelistAssignments((PricelistAssignmentsSearchCriteria)searchCriteria);
                result     = pricelistAssignmentSearchResult.Results.ToArray();
                totalCount = pricelistAssignmentSearchResult.TotalCount;
            }

            return(new ExportableSearchResult()
            {
                Results = ToExportable(result).ToList(),
                TotalCount = totalCount,
            });
        }
Exemplo n.º 5
0
        public IHttpActionResult GetPricelistAssignmentById(string id)
        {
            var assignment = _pricingService.GetPricelistAssignmentsById(new[] { id }).FirstOrDefault();

            return(Ok(assignment));
        }