protected ExpressionStarter <ResCurrentType> ORSearchParameterListPredicateGenerator < ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(List <ISearchParameterBase> SearchParametersList) where ResCurrentType : ResourceCurrentBase <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexStringType : ResourceIndexString <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexTokenType : ResourceIndexToken <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexUriType : ResourceIndexUri <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>, new() where ResIndexReferenceType : ResourceIndexReference <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexQuantityType : ResourceIndexQuantity <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexDateTimeType : ResourceIndexDateTime <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> { var Predicate = LinqKit.PredicateBuilder.New <ResCurrentType>(true); foreach (SearchParameterBase SearchItem in SearchParametersList) { ExpressionStarter <ResCurrentType> NewPredicate = PredicateSearchParameter < ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(SearchItem); Predicate.Extend <ResCurrentType>(NewPredicate, PredicateOperator.Or); } return(Predicate); }
public IEnumerable <User> GetBy(UserFilterModel filterModel) { if (filterModel == null) { throw new ArgumentNullException(nameof(filterModel)); } ExpressionStarter <JToken> filterBuilder = PredicateBuilder.New <JToken>(); if (!string.IsNullOrEmpty(filterModel.Id)) { filterBuilder.And(x => x["Id"].ToString() == filterModel.Id); } if (!string.IsNullOrEmpty(filterModel.Email)) { filterBuilder.And(x => x["Email"].ToString() == filterModel.Email); } if (filterModel.ToDate.HasValue) { filterBuilder.And(x => x["Birthday"].Value <DateTime>() <= filterModel.ToDate.Value); } IEnumerable <User> dataEntities = _dataContext.Items.Value .Where(filterBuilder) .Select(x => x.ToObject <User>()); return(dataEntities ?? Enumerable.Empty <User>()); }
/// <summary> /// Returns a predicate to filter the data by based on the keywords supplied /// </summary> /// <param name="keywords">Keywords to filter by</param> /// <returns>An expression to use for filtering</returns> protected override ExpressionStarter <Employee> BuildSearchFilterPredicate(string[] keywords) { Expression <Func <Employee, bool> > filterExpression = a => true; ExpressionStarter <Employee> predicate = PredicateBuilder.New(filterExpression); bool isFilteredQuery = keywords.Any(); if (!isFilteredQuery) { return(predicate); } predicate = filterExpression = a => false; foreach (var keyword in keywords) { var temp = keyword; if (temp == null) { continue; } predicate = predicate.Or(p => p.FirstName.ToLower().Contains(temp.ToLower())); predicate = predicate.Or(p => p.LastName.ToLower().Contains(temp.ToLower())); predicate = predicate.Or(p => p.Title.ToLower().Contains(temp.ToLower())); } return(predicate); }
/// <summary> /// Returns a default search predicate to filter the data by based on the keywords supplied. /// Override this to supply your own search predicate /// </summary> /// <param name="keywords">Keywords to filter by</param> /// <returns>An expression to use for filtering</returns> protected virtual ExpressionStarter <TEntity> BuildSearchFilterPredicate(string[] keywords) { Expression <Func <TEntity, bool> > filterExpression = a => true; ExpressionStarter <TEntity> predicate = PredicateBuilder.New(filterExpression); return(predicate); }
public async Task <IList <ResourceStore> > GetSearch(Common.Enums.FhirVersion fhirVersion, Common.Enums.ResourceType resourceType, IList <ISearchQueryBase> searchQueryList) { ExpressionStarter <ResourceStore> Predicate = IPredicateFactory.CurrentMainResource(fhirVersion, resourceType); Predicate.Extend(await IPredicateFactory.GetResourceStoreIndexPredicate(fhirVersion, resourceType, searchQueryList), PredicateOperator.And); foreach (var exp in await IPredicateFactory.ChainEntry(_context, resourceType, searchQueryList)) { Predicate.Extend(exp, PredicateOperator.And); } try { IQueryable <ResourceStore> Query = DbSet; Query = Query.AsExpandable().Where(Predicate); return(await Query.OrderBy(z => z.LastUpdated).ToListAsync()); } catch (Exception Exec) { var mesg = Exec.Message; throw Exec; } //string Debug = Predicate.Expand().ToString(); //return await Predicate2.AsExpandable().Where(Predicate).OrderBy(z => z.LastUpdated).ToListAsync(); }
private static void IdSearchParameterPredicateProcessing(List <ISearchParameterBase> SearchParametersList, ResourceSearchExpressionTrees <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> Search, ExpressionStarter <ResCurrentType> MainPredicate) { var IdSearchParamerterList = SearchParametersList.Where(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_id"); if (IdSearchParamerterList != null) { ExpressionStarter <ResCurrentType> NewIdPredicate = null; foreach (var IdSearchParameter in IdSearchParamerterList) { if (IdSearchParameter is SearchParameterToken SearchTypeToken) { NewIdPredicate = LinqKit.PredicateBuilder.New <ResCurrentType>(); foreach (var SearchValue in SearchTypeToken.ValueList) { if (!SearchTypeToken.Modifier.HasValue) { var Expression = Search.MainResourceFhirIdAny(SearchValue.Code); NewIdPredicate = NewIdPredicate.Or(Expression); } } } MainPredicate.Extend <ResCurrentType>(NewIdPredicate, PredicateOperator.And); } SearchParametersList.RemoveAll(x => x.Resource == FHIRAllTypes.Resource.GetLiteral() && x.Name == "_id"); } }
public async Task <bool> IsUserBlacklisted(long targetUserId, IEnumerable <long> usersId) { using (MessengerDbContext context = contextFactory.Create()) { ExpressionStarter <User> usersCondition = PredicateBuilder.New <User>(); usersCondition = usersId.Aggregate(usersCondition, (current, value) => current.Or(user => user.Id == value).Expand()); User targetUser = await context.Users .AsNoTracking() .Include(user => user.BlackList) .Include(user => user.ReverseBlackList) .FirstOrDefaultAsync(user => user.Id == targetUserId) .ConfigureAwait(false); foreach (long userId in usersId) { if (targetUser.ReverseBlackList.Any(opt => opt.Uid == userId) || targetUser.BlackList.Any(opt => opt.BadUid == userId)) { return(true); } } return(false); } }
/// <summary> /// Default predicate for when the client did not provide a predicate for searching. /// In that case use this predicated since the search predicate is always required. /// This predicate just returns TRUE, which means NO filtering. /// </summary> /// <returns>An expression to use for filtering</returns> protected virtual ExpressionStarter <T> BuildDefaultSearchFilterPredicate() { Expression <Func <T, bool> > filterExpression = a => true; ExpressionStarter <T> predicate = PredicateBuilder.New(filterExpression); return(predicate); }
private static ExpressionStarter <T> SwitchOnType <T>(string handleType, ExpressionStarter <T> predicate, object value, string domainName, PropertyComparisonTypeEnum propertyComparison, ExpressionCombinationTypeEnum customCombination, Type type, bool toLower) { switch (handleType) { case "number": predicate = HandleNumber(predicate, value, domainName, propertyComparison, customCombination, type); break; case "text": predicate = HandleText(predicate, value, domainName, propertyComparison, customCombination, type, toLower); break; case "date": predicate = HandleDate(predicate, value, domainName, propertyComparison, customCombination, type); break; case "bool": predicate = HandleBool(predicate, value, domainName, propertyComparison, customCombination); break; default: break; } return(predicate); }
public Task <IEnumerable <PublishedProviderResult> > GetPublishedProviderResultsForSpecificationAndStatus(string specificationId, UpdatePublishedAllocationLineResultStatusModel filterCriteria) { IQueryable <PublishedProviderResult> results = _cosmosRepository.Query <PublishedProviderResult>(enableCrossPartitionQuery: true).Where(m => m.SpecificationId == specificationId && m.FundingStreamResult.AllocationLineResult.Current.Status == filterCriteria.Status); ExpressionStarter <PublishedProviderResult> providerPredicate = PredicateBuilder.New <PublishedProviderResult>(false); foreach (UpdatePublishedAllocationLineResultStatusProviderModel provider in filterCriteria.Providers) { string providerId = provider.ProviderId; providerPredicate = providerPredicate.Or(p => p.ProviderId == providerId); ExpressionStarter <PublishedProviderResult> allocationLinePredicate = PredicateBuilder.New <PublishedProviderResult>(false); foreach (string allocationLineId in provider.AllocationLineIds) { string temp = allocationLineId; allocationLinePredicate = allocationLinePredicate.Or(a => a.FundingStreamResult.AllocationLineResult.AllocationLine.Id == temp); } providerPredicate = providerPredicate.And(allocationLinePredicate); } results = results.AsExpandable().Where(providerPredicate); List <PublishedProviderResult> result = new List <PublishedProviderResult>(results); return(Task.FromResult(result.AsEnumerable())); }
private static void GetBySearchString(this ExpressionStarter <FileStorage> predicate, string searchString) { if (!String.IsNullOrEmpty(searchString)) { predicate.And(x => x.Name.ToLower().Contains(searchString.ToLower())); } }
public static Func <Transaction, bool> CreateTransactionFilter(string currencyCode, DateTime?dateFrom, DateTime?dateTo, string status) { ExpressionStarter <Transaction> predicate = PredicateBuilder.New <Transaction>(true); if (!string.IsNullOrEmpty(currencyCode)) { predicate = predicate.And(c => c.CurrencyCode == currencyCode); } if (dateFrom != null) { predicate = predicate.And(c => c.TransactionDate.CompareTo(dateFrom.Value) >= 0); } if (dateTo != null) { predicate = predicate.And(c => c.TransactionDate.CompareTo(dateTo.Value) <= 0); } if (!string.IsNullOrEmpty(status) && Enum.IsDefined(typeof(TransactionStatusEnum), status)) { predicate = predicate.And(c => c.TransactionStatus == (TransactionStatusEnum)Enum.Parse(typeof(TransactionStatus), status)); } return(predicate.Compile()); }
public ResultHandler <Expression <Func <EventModel, bool> > > BuildExpression(FilterStatement <EventModel> filterStatement) { try { ExpressionStarter <EventModel> result = PredicateBuilder.New <EventModel>(); switch (filterStatement.PropertyName) { case "Audience": var values = JsonConvert.DeserializeObject <IEnumerable <int> >(filterStatement.ValueJson); foreach (var value in values) { result.Or(x => x.Audience == value); } break; default: throw new NotImplementedException("No filter support for this property"); } return(ResultHandler.Ok <Expression <Func <EventModel, bool> > >(result)); } catch (Exception ex) { this._logger.LogError(ex, "MultiCheckboxFilter.BuildExpression Failure"); return(ResultHandler.Fail <Expression <Func <EventModel, bool> > >(ex)); } }
public async Task <bool> ExecuteQueryAsync(Queries.LocationWithNameDoesNotExist query, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(query?.Name) || string.IsNullOrWhiteSpace(this.currentUserProvider?.User?.Name)) { return(false); } using (ApplicationContext context = this.databaseContextProvider.CreateContext()) { ExpressionStarter <Location> predicate = PredicateBuilder.New <Location>(entity => entity.Owner.Equals(this.currentUserProvider.User.Name.ToSha256(), StringComparison.InvariantCultureIgnoreCase) && entity.Name.Equals(query.Name, StringComparison.InvariantCultureIgnoreCase)); if (!string.IsNullOrWhiteSpace(query.ExceptId)) { predicate = predicate.And(entity => !entity.Id.Equals(query.ExceptId, StringComparison.InvariantCultureIgnoreCase)); } return(!await context.Locations.AnyAsync(predicate, cancellationToken).ConfigureAwait(false)); } }
private static ExpressionStarter <T> HandleDate <T>(ExpressionStarter <T> predicate, object value, string domainName, PropertyComparisonTypeEnum propertyComparison, ExpressionCombinationTypeEnum expressionCombination, Type type) { if (value == null) { return(predicate); } if (CheckIfDefaultValue(value, type)) { return(predicate); } Expression <Func <T, bool> > condition = GetExpression <T>(propertyComparison, value, domainName); switch (expressionCombination) { case ExpressionCombinationTypeEnum.And: predicate.And(condition); break; case ExpressionCombinationTypeEnum.Or: predicate.Or(condition); break; default: predicate.And(condition); break; } return(predicate); }
public Expression <Func <User, bool> > GetUserExpression(SearchUserVm templateUser) { ExpressionStarter <User> userCondition = PredicateBuilder.New <User>(); if (!string.IsNullOrWhiteSpace(templateUser.NameFirst)) { userCondition = userCondition.And(user => user.NameFirst.ToLower() == templateUser.NameFirst.ToLower()); } if (!string.IsNullOrWhiteSpace(templateUser.NameSecond)) { userCondition = userCondition.And(user => user.NameSecond.ToLower() == templateUser.NameSecond.ToLower()); } if (!string.IsNullOrWhiteSpace(templateUser.City)) { userCondition = userCondition.And(user => user.City.ToLower() == templateUser.City.ToLower()); } if (!string.IsNullOrWhiteSpace(templateUser.Country)) { userCondition = userCondition.And(user => user.Country.ToLower() == templateUser.Country.ToLower()); } if (templateUser.Birthday != null) { userCondition = userCondition.And(user => user.Birthday == templateUser.Birthday); } if (templateUser.Tag != null) { userCondition = userCondition.And(user => user.Tag == templateUser.Tag); } return((Expression <Func <User, bool> >)userCondition.Expand()); }
private ExpressionStarter <IResourceIndexed> PredicateSearchParameter(SearchParameterBase SearchItem) { var Search = new Search <IResourceIndexed>(); ExpressionStarter <IResourceIndexed> Predicate = LinqKit.PredicateBuilder.New <IResourceIndexed>(); switch (SearchItem.Type) { case SearchParamType.Date: Predicate = DateTimePeriodPredicateBuilder <IResourceIndexed> .Build(Search, Predicate, SearchItem); break; case SearchParamType.Number: { if (SearchItem is SearchParameterNumber) { var SearchTypeNumber = SearchItem as SearchParameterNumber; foreach (var SearchValue in SearchTypeNumber.ValueList) { if (SearchTypeNumber.Name != "page") { //ToDo: more needed here } } } Predicate = NumberPredicateBuilder <IResourceIndexed> .Build(Search, Predicate, SearchItem); } break; case SearchParamType.Quantity: Predicate = QuantityPredicateBuilder <IResourceIndexed> .Build(Search, Predicate, SearchItem); break; case SearchParamType.Reference: Predicate = ReferancePredicateBuilder <IResourceIndexed> .Build(Search, Predicate, SearchItem, IPrimaryServiceRootCache.GetPrimaryRootUrlStoreFromDatabase()); break; case SearchParamType.String: Predicate = StringPredicateBuilder <IResourceIndexed> .Build(Search, Predicate, SearchItem); break; case SearchParamType.Token: Predicate = TokenPredicateBuilder <IResourceIndexed> .Build(Search, Predicate, SearchItem); break; case SearchParamType.Uri: Predicate = UriPredicateBuilder <IResourceIndexed> .Build(Search, Predicate, SearchItem); break; default: throw new System.ComponentModel.InvalidEnumArgumentException(SearchItem.Type.ToString(), (int)SearchItem.Type, typeof(SearchParamType)); } return(Predicate); }
private static void GetByUserGroups(this ExpressionStarter <FileStorage> predicate, IEnumerable <int> userGroupIds) { if (userGroupIds.Count() > 0) { predicate.And(x => x.OwnerId.HasValue && x.Owner.UserInGroups.Any(y => userGroupIds.Contains(y.GroupId)) || x.Permissions.Any(y => !y.EndDate.HasValue && y.Recipient.UserInGroups.Any(z => userGroupIds.Contains(z.GroupId)))); } }
protected void PredicateAnd(Expression <Func <TEntity, bool> > expression) { if (expression != null) { hasPredicate = true; predicate = predicate.And(expression); } }
public Expression <Func <Channel, bool> > GetChannelExpression(string query) { ExpressionStarter <Channel> chatCondition = PredicateBuilder.New <Channel>(); string lowerQuery = query.ToLowerInvariant(); chatCondition = chatCondition.Or(chat => chat.SearchVector.Matches(EF.Functions.PhraseToTsQuery("simple", query))); return((Expression <Func <Channel, bool> >)chatCondition.Expand()); }
private static void GetByDepartments(this ExpressionStarter <FileStorage> predicate, IEnumerable <int> departmentIds) { if (departmentIds.Count() > 0) { predicate.And(x => x.ClientId.HasValue && x.Client.Departments.Any(y => departmentIds.Contains(y.Id)) || x.OwnerId.HasValue && x.Owner.DepartmentId.HasValue && departmentIds.Contains(x.Owner.DepartmentId.Value) || x.Permissions.Any(y => !y.EndDate.HasValue && y.Recipient.DepartmentId.HasValue && departmentIds.Contains(y.Recipient.DepartmentId.Value))); } }
public static Expression <Func <T, bool> > AndIf <T>(this ExpressionStarter <T> expression, Expression <Func <T, bool> > expr2) { if (expr2 != null) { return(expression.And(expr2)); } return(expression); }
/// <summary> /// Returns a paged IEnumerable of the given entity type from the database. /// </summary> /// <param name="pageNumber">The page number to return when paging</param> /// <param name="pageSize">The number of items to return per page</param> /// <param name="totalRecords">This is an output parameter which returns the total number of items returned by the query</param> /// <param name="sortColumn">The sort column - must be provided</param> /// <param name="sortDirection">The sort direction - must be provided</param> /// <param name="searchPredicate">An optional search predicate</param> /// <returns></returns> public IEnumerable <TEntity> FindAllEntitiesByCriteria( int?pageNumber, int?pageSize, out int totalRecords, string sortColumn, string sortDirection, ExpressionStarter <TEntity> searchPredicate) { return(FindAllByCriteria( pageNumber, pageSize, out totalRecords, sortColumn, sortDirection, searchPredicate)); }
public LinqQuery <TEntity> Or(Expression <Func <TEntity, bool> > expression) { if (expression != null) { hasPredicate = true; predicate = predicate.Or(expression); } return(this); }
/// <summary> /// Gets the value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="p">The p.</param> /// <param name="predicate">The predicate.</param> /// <param name="searchValue"></param> private void GetPredicate <T>(DataTablesColumnModel p, ExpressionStarter <T> predicate, string searchValue) { // PropertyInfo pi = typeof(T).GetProperty(p.Data); var exp = BuildExpression <T>(searchValue, p.Data); if (exp != null) { predicate.Or(exp); } }
public int GetPageCount(int itemsPerPage, ExpressionStarter <T> expression) { var list = service.GetAll() .Where(expression) .ToList(); int pageCount = (int)Math.Ceiling((double)list.Count / (double)itemsPerPage); return(pageCount); }
public async Task <ExpressionStarter <ResourceStore> > GetResourceStoreIndexPredicate(Common.Enums.FhirVersion fhirVersion, Common.Enums.ResourceType resourceType, IList <ISearchQueryBase> SearchQueryList) { IEnumerable <ISearchQueryBase> ChainedSearchQueryList = SearchQueryList.Where(x => x.ChainedSearchParameter is object); IEnumerable <ISearchQueryBase> NoChainedSearchQueryList = SearchQueryList.Where(x => x.ChainedSearchParameter is null); //Below must be true 'PredicateBuilder.New<ResourceStore>(true)' in order to get all resource when no query string ExpressionStarter <ResourceStore> Predicate = PredicateBuilder.New <ResourceStore>(true); foreach (var Search in NoChainedSearchQueryList) { switch (Search.SearchParamTypeId) { case Common.Enums.SearchParamType.Number: IResourceStorePredicateFactory.NumberIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.QuantityIndexList.Any(x.Compile()))); break; case Common.Enums.SearchParamType.Date: IResourceStorePredicateFactory.DateTimeIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.DateTimeIndexList.Any(x.Compile()))); break; case Common.Enums.SearchParamType.String: IResourceStorePredicateFactory.StringIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.StringIndexList.Any(x.Compile()))); break; case Common.Enums.SearchParamType.Token: IResourceStorePredicateFactory.TokenIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.TokenIndexList.Any(x.Compile()))); break; case Common.Enums.SearchParamType.Reference: (await IResourceStorePredicateFactory.ReferenceIndex(Search)).ForEach(x => Predicate = Predicate.Or(y => y.ReferenceIndexList.Any(x.Compile()))); break; case Common.Enums.SearchParamType.Composite: Predicate = await IResourceStorePredicateFactory.CompositeIndex(this, Search); break; case Common.Enums.SearchParamType.Quantity: IResourceStorePredicateFactory.QuantityIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.QuantityIndexList.Any(x.Compile()))); break; case Common.Enums.SearchParamType.Uri: IResourceStorePredicateFactory.UriIndex(Search).ForEach(x => Predicate = Predicate.Or(y => y.UriIndexList.Any(x.Compile()))); break; case Common.Enums.SearchParamType.Special: throw new Common.Exceptions.FhirFatalException(System.Net.HttpStatusCode.InternalServerError, new string[] { $"Attempt to search with a SearchParameter of type: {Common.Enums.SearchParamType.Special.GetCode()} which is not supported by this server." }); default: break; } Predicate = Predicate.Extend(Predicate, PredicateOperator.And); } return(Predicate); }
public static ExpressionStarter <ToDoEntity> CreateSearchPredicate(SearchRequestDto request) { ExpressionStarter <ToDoEntity> predicate = PredicateBuilder.New <ToDoEntity>(true); if (request.TableId != null) { predicate.And(x => x.TableId == request.TableId); } return(predicate); }
public Expression <Func <User, bool> > GetUserExpression(string query) { ExpressionStarter <User> userCondition = PredicateBuilder.New <User>(); string lowerQuery = query.ToLowerInvariant(); userCondition = userCondition.Or(user => user.Phones.Any(opt => opt.PhoneNumber == query) || user.Emails.Any(opt => opt.EmailAddress.ToLower() == query.ToLowerInvariant()) || user.SearchVector.Matches(EF.Functions.PhraseToTsQuery("simple", query))); return((Expression <Func <User, bool> >)userCondition.Expand()); }
protected virtual IEnumerable <TEntity> FindAllEntitiesByCriteria( int?pageNumber, int?pageSize, out int totalRecords, string sortColumn, string sortDirection, out int offset, out int offsetUpperBound, out int totalNumberOfPages, OperationResult result, ExpressionStarter <TEntity> searchPredicate) { if (Repository == null) { throw new Exception(nameof(Repository)); } if (sortColumn.IsNullOrWhiteSpace()) { Error.ArgumentNull(nameof(sortColumn)); } if (sortDirection.IsNullOrWhiteSpace()) { Error.ArgumentNull(nameof(sortDirection)); } int pageIndex = pageNumber ?? 1; int sizeOfPage = pageSize ?? 10; string[] keywords = result.ObjectsDictionary["keywords"] as string[]; var items = Repository.FindAllEntitiesByCriteria( pageIndex, sizeOfPage, out totalRecords, sortColumn, sortDirection, searchPredicate); totalNumberOfPages = (int)Math.Ceiling((double)totalRecords / sizeOfPage); offset = (pageIndex - 1) * sizeOfPage + 1; offsetUpperBound = offset + (sizeOfPage - 1); if (offsetUpperBound > totalRecords) { offsetUpperBound = totalRecords; } result.AddResultObject("sortCol", sortColumn); result.AddResultObject("sortDir", sortDirection); result.AddResultObject("offset", offset); result.AddResultObject("pageIndex", pageIndex); result.AddResultObject("sizeOfPage", sizeOfPage); result.AddResultObject("offsetUpperBound", offsetUpperBound); result.AddResultObject("totalNumberOfRecords", totalRecords); result.AddResultObject("totalNumberOfPages", totalNumberOfPages); result.AddResultObject("searchTerms", string.Join(",", keywords.Select(i => i.ToString()))); return(items); }