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())); }
public IHttpActionResult GetSearch([FromUri(Name = "")] PassSearchQueryModel queryModel) { if (queryModel == null || !ModelState.IsValid) { return(this.Error().InvalidParameters()); } // Search var freeTextMatchRules = new StringMatchRules(StringMatchHowManyWordsToMatch.AllWords, StringMatchWordOrders.AnyOrder, StringMatchWordComparisons.ContainsWord, false, new Char[] { ' ', ',' }, null); var passes = _passRepository.Search(queryModel, freeTextMatchRules); // Map to model var passModels = Mappings.MapToPassModels(passes.Items.ToList(), _passRepository, _mapper); var results = new PagedQueryResult <PassModel>(passes.TotalCount, passModels); return(Ok(results)); }
protected CallMethodResult Search( string name, bool?isLibraried, StringMatchHowManyWordsToMatch howManyWordsToMatch, StringMatchWordOrders wordOrder, StringMatchWordComparisons wordComparison, bool caseSensitive) { var queryModel = new PassSearchQueryModel { Name = name, IsLibraried = isLibraried }; var freeTextMatchRules = new StringMatchRules(howManyWordsToMatch, wordOrder, wordComparison, caseSensitive, new Char[] { ' ', ',' }, null); var res = Repository.Search(queryModel, freeTextMatchRules); TestContext.LastOperationCount = res?.Items?.Count ?? 0; TestContext.LastCollectionResult = res?.Items?.Cast <object>().ToList(); TestContext.LastSingleResult = TestContext.LastOperationCount == 1 ? res.Items.First() : null; return(CallMethodResult.CreateHandled()); }