예제 #1
0
        public static IFullTextSearchConditionBuilder StartAllWith(this IFullTextSearchConditionBuilder builder, params string[] values)
        {
            if (values?.Any() ?? false)
            {
                var b = builder.StartWith(values.First());
                foreach (var value in values.Skip(1))
                {
                    builder = b.And();
                    b       = builder.StartWith(value);
                }
            }

            return(builder);
        }
예제 #2
0
        protected IQueryable <CampaignEntitySearchQueryModel> ApplyCampaignSearchFilters(CampaignSearchQueryModel queryModel, IQueryable <CampaignEntitySearchQueryModel> query)
        {
            if (!string.IsNullOrWhiteSpace(queryModel.Description))
            {
                var ftsQueryText = _searchConditionBuilder.StartWith(queryModel.Description).Build();

                query = query.Where(q =>
                                    //campaign
                                    EF.Functions.Contains(
                                        EF.Property <string>(q.Campaign, Entities.Tenant.Campaigns.Campaign.SearchTokensFieldName),
                                        ftsQueryText) ||
                                    q.Campaign.CampaignGroup.Contains(queryModel.Description) ||
                                    q.Campaign.Name.Contains(queryModel.Description) ||
                                    q.Campaign.ExternalId.Contains(queryModel.Description) ||
                                    q.Campaign.BusinessType.Contains(queryModel.Description) ||
                                    //demographics
                                    q.Demographic.ShortName.Contains(queryModel.Description) ||
                                    //product
                                    q.Product.Name.Contains(queryModel.Description) ||
                                    EF.Functions.Contains(EF.Property <string>(q.Product, Product.SearchFieldName),
                                                          ftsQueryText) ||
                                    //advertiser
                                    q.Advertiser.Name.Contains(queryModel.Description) ||
                                    EF.Functions.Contains(EF.Property <string>(q.Advertiser, Advertiser.SearchFieldName),
                                                          ftsQueryText) ||
                                    //agency
                                    q.Agency.Name.Contains(queryModel.Description) ||
                                    EF.Functions.Contains(EF.Property <string>(q.Agency, Agency.SearchFieldName),
                                                          ftsQueryText) ||
                                    //clash
                                    q.Clash.Externalref.Contains(queryModel.Description) ||
                                    q.Clash.Description.Contains(queryModel.Description)
                                    );
            }

            if (queryModel.BusinessTypes != null && queryModel.BusinessTypes.Any())
            {
                query = query.Where(q => queryModel.BusinessTypes.Contains(q.Campaign.BusinessType));
            }

            if (queryModel.ClashCodes != null && queryModel.ClashCodes.Any())
            {
                query = query.Where(q => queryModel.ClashCodes.Contains(q.Product.ClashCode));
            }

            if (queryModel.CampaignIds != null && queryModel.CampaignIds.Any())
            {
                query = query.Where(q => queryModel.CampaignIds.Contains(q.Campaign.ExternalId));
            }

            if (queryModel.ProductIds != null && queryModel.ProductIds.Any())
            {
                query = query.Where(q => queryModel.ProductIds.Contains(q.Campaign.Product));
            }

            if (queryModel.AgencyIds != null && queryModel.AgencyIds.Any())
            {
                query = query.Where(q => queryModel.AgencyIds.Contains(q.Agency.ExternalIdentifier));
            }

            if (queryModel.MediaSalesGroupIds != null && queryModel.MediaSalesGroupIds.Any())
            {
                query = query.Where(q => queryModel.MediaSalesGroupIds.Contains(q.AgencyGroup.Code));
            }

            if (queryModel.ProductAssigneeIds != null && queryModel.ProductAssigneeIds.Any())
            {
                List <int> productAssigneeIds = queryModel.ProductAssigneeIds
                                                .Select(s => Int32.TryParse(s, out int n) ? n : (int?)null)
                                                .Where(n => n.HasValue)
                                                .Select(n => n.Value)
                                                .ToList();

                query = query.Where(q => productAssigneeIds.Contains(q.Person.ExternalIdentifier));
            }

            if (queryModel.ReportingCategories != null && queryModel.ReportingCategories.Any())
            {
                query = query.Where(q => queryModel.ReportingCategories.Contains(q.Product.ReportingCategory));
            }

            if (queryModel.AdvertiserIds != null && queryModel.AdvertiserIds.Any())
            {
                query = query.Where(q => queryModel.AdvertiserIds.Contains(q.Advertiser.ExternalIdentifier));
            }

            return(query);
        }