Exemple #1
0
        public PagedQueryResult <Pass> Search(PassSearchQueryModel queryModel, StringMatchRules freeTextMatchRules)
        {
            var query = PassQuery;

            if (queryModel.IsLibraried != null)
            {
                query = queryModel.IsLibraried.Value
                    ? query.Where(e => e.IsLibraried == true)
                    : query.Where(e => e.IsLibraried == null || e.IsLibraried == false);
            }

            if (!string.IsNullOrWhiteSpace(queryModel.Name))
            {
                var searchCondition = _searchConditionBuilder
                                      .StartAnyWith(queryModel.Name.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))
                                      .Build();

                query = query.Where(p => EF.Functions.Contains(p.Name, searchCondition));
            }

            query = (queryModel.OrderBy?.Any() ?? false)
                ? query.OrderByMultipleItems(queryModel.OrderBy)
                : query.OrderBy(p => p.Name);

            List <Pass> passList = _mapper.Map <List <Pass> >(
                query.Where(e => freeTextMatchRules.IsMatches(e.Name, queryModel.Name)).AsNoTracking(),
                opt => opt.UseEntityCache(_salesAreaByIdCache));

            return(new PagedQueryResult <Pass>(passList.Count,
                                               passList.ApplyPaging(queryModel.Skip, queryModel.Top).ToList()));
        }
Exemple #2
0
        private List <RunExtendedSearchModel> ApplyFreeTextMatchRules(List <RunExtendedSearchModel> runs, StringMatchRules freeTextMatchRules, string description)
        {
            if (string.IsNullOrWhiteSpace(description))
            {
                return(runs);
            }

            return(runs.Where(r => freeTextMatchRules.IsMatches(r.Description, description) ||
                              (!string.IsNullOrWhiteSpace(r.Author?.Name) &&
                               freeTextMatchRules.IsMatches(r.Author.Name, description)) ||
                              freeTextMatchRules.IsMatches(r.Id.ToString(), description) ||
                              r.ScenarioIds.Any(id => freeTextMatchRules.IsMatches(id, description)) ||
                              r.ScenarioNames.Any(name => freeTextMatchRules.IsMatches(name, description)) ||
                              r.PassNames.Any(name => freeTextMatchRules.IsMatches(name, description)) ||
                              r.PassIds.Any(id => freeTextMatchRules.IsMatches(id, description))).ToList());
        }