Exemple #1
0
        public PagedQueryResult <ProductAdvertiserModel> Search(AdvertiserSearchQueryModel searchQuery, DateTime onDate)
        {
            lock (_session)
            {
                var where = new List <Expression <Func <Product_BySearch.IndexedFields, bool> > >();
                if (!string.IsNullOrWhiteSpace(searchQuery.AdvertiserNameorRef))
                {
                    var termsList =
                        searchQuery.AdvertiserNameorRef.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    where.AddRange(termsList.Select(
                                       term => (Expression <Func <Product_BySearch.IndexedFields, bool> >)(p => p.TokenizedAdvertiser
                                                                                                           .StartsWith(term))));
                }
                var items = DocumentSessionExtensions
                            .GetAll <Product_BySearch.IndexedFields, Product_BySearch, ProductAdvertiserTransformer_BySearch, ProductAdvertiserModel>(_session,
                                                                                                                                                      where.Any() ? where.AggregateAnd() : null,
                                                                                                                                                      out int totalResult, null, null,
                                                                                                                                                      searchQuery.Skip,
                                                                                                                                                      searchQuery.Top);

                var totalCount = searchQuery.IncludeTotalCount ? totalResult : 0;

                return(new PagedQueryResult <ProductAdvertiserModel>(totalCount, items));
            }
        }
Exemple #2
0
        public PagedQueryResult <ProductAdvertiserModel> Search(AdvertiserSearchQueryModel searchQuery, DateTime onDate)
        {
            if (searchQuery == null)
            {
                throw new ArgumentNullException(nameof(searchQuery));
            }

            var query = string.Empty;

            if (!string.IsNullOrWhiteSpace(searchQuery.AdvertiserNameorRef))
            {
                query = _searchConditionBuilder.StartAllWith(
                    searchQuery.AdvertiserNameorRef.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)).Build();
            }

            var dbQuery =
                (from p in _dbContext.Query <Entities.Tenant.Products.Product>()
                 join pa in _dbContext.Query <ProductAdvertiser>() on p.Uid equals pa.ProductId
                 join a in _dbContext.Query <Advertiser>() on pa.AdvertiserId equals a.Id
                 where pa.StartDate <= onDate && pa.EndDate > onDate
                 select a).AsQueryable();

            var items = (string.IsNullOrWhiteSpace(query)
                    ? dbQuery
                    : dbQuery
                         .Where(a => EF.Functions.Contains(
                                    EF.Property <string>(a, Entities.Tenant.Advertiser.SearchFieldName), query)))
                        .Distinct().OrderBy(x => x.ExternalIdentifier)
                        .ProjectTo <ProductAdvertiserModel>(_mapper.ConfigurationProvider);

            var totalCount = searchQuery.IncludeTotalCount ? items.Count() : 0;

            return(new PagedQueryResult <ProductAdvertiserModel>(totalCount,
                                                                 items.ApplyPaging(searchQuery.Skip, searchQuery.Top).ToList()));
        }
        protected CallMethodResult SearchAdvertiser(string nameOrRef)
        {
            var queryModel = new AdvertiserSearchQueryModel
            {
                AdvertiserNameorRef = nameOrRef,
            };
            var res = Repository.Search(queryModel, _clock.GetCurrentInstant().ToDateTimeUtc());

            TestContext.LastOperationCount   = res?.Items?.Count ?? 0;
            TestContext.LastCollectionResult = res?.Items;
            TestContext.LastSingleResult     = TestContext.LastOperationCount == 1 ? res.Items.First() : null;

            return(CallMethodResult.CreateHandled());
        }
Exemple #4
0
        public IHttpActionResult GetAdvertiser([FromUri] AdvertiserSearchQueryModel queryModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters("One or more of the required query parameters are missing."));
            }
            if (queryModel == null)
            {
                queryModel = new AdvertiserSearchQueryModel();
            }

            var products = _repository.Search(queryModel, _clock.GetCurrentInstant().ToDateTimeUtc());

            var searchModel = new SearchResultModel <ProductAdvertiserModel>()
            {
                Items = products.Items.ToList(),

                TotalCount = products.TotalCount
            };

            return(Ok(searchModel));
        }
 public PagedQueryResult <ProductAdvertiserModel> Search(AdvertiserSearchQueryModel searchQuery, DateTime onDate)
 {
     throw new NotImplementedException();
 }