public virtual PaginationResult <TEntity> AdvancedPage(int id, [FromBody] AdvancedPageModel model) { try { var pageResult = this.CurrentService.GetAdvancedPage(model); return(pageResult); } catch (Exception ex) { //return throw ex; } }
public async Task <PaginationResult <ActiveDirectory> > AdvancedPage([FromBody] AdvancedPageModel model) { logger.LogDebug("Entered ActiveDirectory Controller AdvancedPage Action"); try { var pageResult = await this.CurrentService.GetAdvancedPage(model); return(pageResult); } catch (Exception ex) { throw ex; } }
public virtual PaginationResult <TEntity> GetPage(int offSet, int limit, string searchCriteria = null, string sortName = null, string sortOrder = "desc", ParameterExpression genericType = null, Expression extraExpr = null) { var query = (IQueryable <TEntity>)null; var advancedPageModel = new AdvancedPageModel() { AdvancedSearch = new List <AdvancedSearch>(), SearchLimit = limit, SearchOffSet = offSet, SearchString = searchCriteria, SortOrder = sortOrder, SortString = sortName }; return(this.Repository.GetAdvancedPage(offSet, limit, searchCriteria, sortName, sortOrder, advancedPageModel, query)); }
/// <summary> /// Gets a page of <see cref="ActiveDirectory"/> from the database by /// the <see cref="AdvancedPageModel"/> settings /// </summary> /// <param name="model"><see cref="AdvancedPageModel"/> passed in from the controller</param> /// <returns><see cref="PaginationResult{T}"/> of <see cref="ActiveDirectory"/></returns> public override Task <PaginationResult <ActiveDirectory> > GetAdvancedPage(AdvancedPageModel model) { /* * An override that is common is to change the query based on a users role * * var query = this.Repository.GetFullEntity(); * if (!Utils.UserInfo.IsUserInRole("Admin")) * { * var user = this.ActiveDirectoryService.GetCurrentlyLoggedInUser(); * query = query.Where(x => x.CreatedUserId == user.ActiveDirectoryID); * } * return this.Repository.GetAdvancedPage(model.SearchOffSet, model.SearchLimit, model.SearchString, model.SortString, model.SortOrder, model, query); */ logger.LogDebug("Entered ActiveDirectoryService GetAdvancedPage"); return(base.GetAdvancedPage(model)); }
/// <summary> /// Returns a page of data of the entity /// </summary> /// <param name="offSet">The row offset on the database</param> /// <param name="limit">The number of records to return</param> /// <param name="searchCriteria">The criteria to search on the searchable attribute</param> /// <param name="sortName">The name of the property to sort on</param> /// <param name="sortOrder">The direction to sort (desc/asc)</param> /// <param name="model">The AdvancedPageModel</param> /// <returns>A PaginationResult that contains the entities</returns> public Task <PaginationResult <TEntity> > GetAdvancedPage(int offSet, int limit, string searchCriteria = null, string sortName = null, string sortOrder = "desc", AdvancedPageModel model = null) { return(this.Repository.GetAdvancedPage(offSet, limit, searchCriteria, sortName, sortOrder, model)); }
/// <summary> /// Returns a page of data of the entity /// </summary> /// <param name="model">The AdvancedPageModel</param> /// <returns>A PaginationResult that contains the entities</returns> public virtual Task <PaginationResult <TEntity> > GetAdvancedPage(AdvancedPageModel model) { return(this.Repository.GetAdvancedPage(model.SearchOffSet, model.SearchLimit, model.SearchString, model.SortString, model.SortOrder, model)); }
/// <summary> /// Gets a page of <see cref="ActiveDirectory"/> from the database /// </summary> /// <param name="offSet">Row offset for the page</param> /// <param name="limit">Number of rows to return</param> /// <param name="searchCriteria">The search string for the simple search</param> /// <param name="sortName">The property name of <see cref="ActiveDirectory"/> to sort</param> /// <param name="sortOrder">The sort direction (asc or desc)</param> /// <param name="model"><see cref="AdvancedPageModel"/></param> /// <param name="query">Extra query to further filter the page</param> /// <returns><see cref="PaginationResult{T}"/> of <see cref="ActiveDirectory"/></returns> public override Task <PaginationResult <ActiveDirectory> > GetAdvancedPage(int offSet, int limit, string searchCriteria = null, string sortName = null, string sortOrder = "desc", AdvancedPageModel model = null, IQueryable <ActiveDirectory> query = null) { return(base.GetAdvancedPage(offSet, limit, searchCriteria, sortName, sortOrder, model, query)); }
/// <summary> /// Gets the Linq.Expression that will represent the AdvancedPaging query /// </summary> /// <param name="model">The AdvancedPageModel</param> /// <param name="genericType">The ParameterExpression that represents the Entity</param> /// <returns>The Expression for the AdvancedPage</returns> public Expression GetAdvancedSearchRestrictions(AdvancedPageModel model, ParameterExpression genericType) { Expression restrictions = null; if (model.AdvancedSearch == null) { return(restrictions); } foreach (var adv in model.AdvancedSearch) { var valueA = (object)(adv.IntValue.HasValue ? adv.IntValue.Value : adv.Value); var key = typeof(TEntity).GetPropertyExpressionFromSubProperty(adv.PropertyName, genericType); //if (key.Type == typeof(int)) //{ // key = ((MemberExpression)key).ConvertToType(TypeCode.String); //}; var propertyType = typeof(TEntity).FollowPropertyPath(adv.PropertyName).PropertyType; var value = valueA != null?Expression.Constant(RepositoryExtensions.ChangeType(valueA, propertyType)) : null; Expression addedExpression = null; switch (adv.TypeOfSearch) { case AdvancedSearchType.IsNull: addedExpression = RepositoryExtensions.NullableEqual(key, Expression.Constant(null)); break; case AdvancedSearchType.IsNotNull: addedExpression = RepositoryExtensions.NullableNotEqual(key, Expression.Constant(null)); break; case AdvancedSearchType.In: addedExpression = RepositoryExtensions.InExpression <TEntity>(genericType, adv.PropertyName, adv.ListValue); break; case AdvancedSearchType.NotIn: addedExpression = Expression.Not(RepositoryExtensions.InExpression <TEntity>(genericType, adv.PropertyName, adv.ListValue)); break; case AdvancedSearchType.Equal: addedExpression = RepositoryExtensions.NullableEqual(key, value); break; case AdvancedSearchType.NotEqual: addedExpression = RepositoryExtensions.NullableNotEqual(key, value); break; case AdvancedSearchType.LessThan: addedExpression = RepositoryExtensions.NullableLessThan(key, value); break; case AdvancedSearchType.LessThanEqual: addedExpression = RepositoryExtensions.NullableLessThanOrEqualTo(key, value); break; case AdvancedSearchType.GreaterThan: addedExpression = RepositoryExtensions.NullableGreaterThan(key, value); break; case AdvancedSearchType.GreaterThanEqual: addedExpression = RepositoryExtensions.NullableGreaterThanOrEqualTo(key, value); break; case AdvancedSearchType.Between: var lowerBound = Expression.GreaterThanOrEqual(key, Expression.Constant(Convert.ChangeType(adv.Value, propertyType))); var upperBound = Expression.LessThanOrEqual(key, Expression.Constant(Convert.ChangeType(adv.Value2, propertyType))); addedExpression = Expression.AndAlso(lowerBound, upperBound); break; case AdvancedSearchType.NotLike: addedExpression = Expression.Not(RepositoryExtensions.Contains(key, valueA)); break; case AdvancedSearchType.Like: default: addedExpression = RepositoryExtensions.Contains(key, valueA); break; } //add the new expression to the list restrictions = restrictions == null ? addedExpression : Expression.AndAlso(restrictions, addedExpression); } return(restrictions); }
/// <summary> /// Returns a page of data of the entity /// </summary> /// <param name="offSet">The row offset on the database</param> /// <param name="limit">The number of records to return</param> /// <param name="searchCriteria">The criteria to search on the searchable attribute</param> /// <param name="sortName">The name of the property to sort on</param> /// <param name="sortOrder">The direction to sort (desc/asc)</param> /// <param name="model">The AdvancedPageModel</param> /// <param name="query">Extra query to filter down the entity</param> /// <returns>A PaginationResult that contains the entities</returns> public async virtual Task <PaginationResult <TEntity> > GetAdvancedPage(int offSet, int limit, string searchCriteria = null, string sortName = null, string sortOrder = "desc", AdvancedPageModel model = null, IQueryable <TEntity> query = null) { //create the restrictions if needed var genericType = Expression.Parameter(typeof(TEntity)); var restrictions = !string.IsNullOrWhiteSpace(searchCriteria) ? this.GetSearchRestrictions(searchCriteria, genericType) : null; var advRestrictions = this.GetAdvancedSearchRestrictions(model, genericType); var expr = restrictions != null && advRestrictions != null ? Expression.AndAlso(restrictions, advRestrictions) : restrictions ?? advRestrictions; //set the query if (query == null) { query = this.GetFullEntity(); } //get the row count var rowCount = GetPageRowCount(expr, genericType, query); //get the search results var searchResults = await GetSearchResults(expr, limit, offSet, sortName, sortOrder, genericType, query); //return the pagination model return(new PaginationResult <TEntity> { Rows = searchResults, Total = rowCount }); }