public GridResults ApplyPaging <T>(IGridDataSource <T> source, GridDataRequest paging, List <EntityDTO> list) where T : DomainEntity { var recordCount = source.TotalCount(); var pageCount = (int)Math.Ceiling(recordCount / (double)paging.ResultsPerPage); if (pageCount < paging.Page) { paging.Page = pageCount; } return(new GridResults { page = paging.Page, records = recordCount, total = pageCount, items = list }); }
public GridResults RunGrid(GridDefinition <TEntity> grid, IGridDataSource <TEntity> source, GridDataRequest request) { if (request.ResultsPerPage > grid.MaxCount) { request.ResultsPerPage = grid.MaxCount; } grid.SortBy.ApplyDefaultSorting(request); applyCriteria(request, grid, source); applyRestrictions(source); var data = source.Fetch(request); var actions = grid.Columns.Select(col => col.CreateDtoFiller(data, _formatter, _urls)); var list = createEntityDtos(data, actions); // TODO -- needs some UT's return(ApplyPaging(source, request, list)); }
private void applyCriteria <T>(GridDataRequest paging, GridDefinition <T> grid, IGridDataSource <T> source) where T : DomainEntity { var requests = paging.Criterion.Select(x => { var expression = grid.PropertyExpressionFor(x.property); return(new FilterRequest <T>(x, _converter, expression)); }); requests.Each(req => source.ApplyCriteria(req, _queryService)); }
public int GetCount(IGridDataSource <TEntity> source) { applyRestrictions(source); return(source.TotalCount()); }
private void applyRestrictions(IGridDataSource <TEntity> source) { source.ApplyRestrictions(filter => _restrictions.Each(r => r.Apply(filter))); }