public ActionResult <PageViewModel <EnvironmentViewModel> > GetEnvironments( [FromQuery] PageFilter pageFilter) { var enviromnments = _repo.GetPage(pageFilter); return(Ok(_mapper.Map <PageViewModel <EnvironmentViewModel> >(enviromnments))); }
/// <summary> /// Convert the whole ResultSet into a Page objects. /// </summary> /// <param name="rs">The ResultSet to process.</param> /// <returns>The Initialize Page objects</returns> public T Handle(DbDataReader rs) { T result = default(T); PageFilter filter = null; bool firstTime = true; while (rs.Read()) { if (firstTime) { filter = processor.ToBean <PageFilter>(rs, typeof(PageFilter)); firstTime = false; } string fieldId = rs["FilterFieldId"].ToString(); PageFilterField field = processor.ToBean <PageFilterField>(rs, typeof(PageFilterField)); filter.Fields.Add(field); } result = (T)Convert.ChangeType(filter, type); return(result); }
public ActionResult <PageViewModel <LevelViewModel> > GetLevels( [FromQuery] PageFilter pageFilter) { var levels = _repo.GetPage(pageFilter); return(Ok(_mapper.Map <PageViewModel <LevelViewModel> >(levels))); }
public ActionResult <PageViewModel <UserViewModel> > Users( [FromQuery] PageFilter pageFilter) { var users = _userRepository.GetPage(pageFilter); return(Ok(_mapper.Map <PageViewModel <UserViewModel> >(users))); }
private TagBuilder BuildPageInputTag(string text) { IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext); TagBuilder tag = new TagBuilder("input"); tag.Attributes["type"] = "text"; tag.Attributes["value"] = text; tag.Attributes["data-current"] = text; tag.Attributes["data-min"] = "1"; tag.Attributes["data-max"] = PageInfo.TotalPages.ToString(); tag.Attributes["data-url"] = urlHelper.Action(PageAction, new { page = -1, sort = PageInfo.Sort, ascending = PageInfo.Ascending, filter = PageFilter?.ToString() }); tag.AddCssClass("pagebox"); if (!string.IsNullOrWhiteSpace(PageTitle)) { tag.Attributes["title"] = PageTitle; } TagBuilder listItemTag = new TagBuilder("li"); listItemTag.AddCssClass("page-item active"); listItemTag.InnerHtml.AppendHtml(tag); return(tag); }
public Collection(List <T> items, int totalItems, PageFilter pageFilter) { Items = items; TotalItems = totalItems; PageSize = pageFilter.PageSize; Page = pageFilter.Page; }
public void When_I_Scan_with_a_PageFilter_I_get_the_expected_results() { var client = new HBaseClient(RequestOptionsFactory.GetDefaultOptions()); var scanner = new Scanner(); var filter = new PageFilter(2); scanner.Filter = filter.ToEncodedString(); ScannerInformation scanInfo = null; try { scanInfo = client.CreateScannerAsync(_tableName, scanner).Result; var actualRecords = RetrieveResults(scanInfo).ToList(); actualRecords.Count.ShouldBeGreaterThanOrEqualTo(2); } finally { if (scanInfo != null) { client.DeleteScannerAsync(_tableName, scanInfo).Wait(); } } }
/// <summary> /// Stvara polje za prikaz trenutne stranice i unos željene stranice /// </summary> /// <param name="text">Broj trenutne stranice</param> /// <returns></returns> private TagBuilder BuildPageInputTag(string text) { IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext); TagBuilder tag = new TagBuilder("input"); tag.MergeAttribute("type", "text"); tag.Attributes["value"] = text; tag.Attributes["data-current"] = text; tag.Attributes["data-min"] = "1"; tag.Attributes["data-max"] = PageInfo.TotalPages.ToString(); tag.Attributes["data-url"] = urlHelper.Action(PageAction, new { page = -1, sort = PageInfo.Sort, ascending = PageInfo.Ascending, filter = PageFilter?.ToString() }); tag.AddCssClass("pagebox");//da ga se može pronaći if (PageClassesEnabled) { tag.AddCssClass(PageClass); tag.AddCssClass(PageClassSelected); } return(tag); }
public async Task <EquipmentResponse> GetEquipment(PageFilter filter) { EquipmentResponse _response = new EquipmentResponse(); try { List <EquipmentEntity> results = await _context.Equipment.Where(x => x.IsDeleted == false).OrderByDynamic(filter.Column, filter.Descending).Skip(filter.Index * filter.Count).Take(filter.Count).ToListAsync(); _response.Code = "E000"; _response.Message = _localizer["success"]; _response.DataCount = await _context.Equipment.Where(x => x.IsDeleted == false).CountAsync(); _response.ResponseDate = DateTime.Now.ToUniversalTime(); _response.Results.AddRange(results); } catch (Exception) { _response.Code = "E999"; _response.Message = _localizer["error"]; _response.DataCount = 0; _response.ResponseDate = DateTime.Now.ToUniversalTime(); _response.Results = null; } return(_response); }
protected void Page_Load(object sender, EventArgs e) { System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代码 using (DNetContext db = new DNetContext()) { StringBuilder sql = new StringBuilder(); List <DbParameter> parameters = new List <DbParameter>(); sql.AppendFormat(@"SELECT {0},A.AuthorName FROM Book B LEFT JOIN Author A ON A.AuthorID=B.AuthorID WHERE", SqlBuilder.GetSelectAllFields <Book>("B")); sql.Append(" B.BookID>@BookID "); parameters.Add(db.GetDbParameter("BookID", 1)); PageFilter pageFilter = new PageFilter { PageIndex = 1, PageSize = 5 }; pageFilter.OrderText = "B.BookID ASC"; PageDataSource <Book> books = db.GetPage <Book>(sql.ToString(), pageFilter, parameters.ToArray()); List <Book> bks = db.GetList <Book>(sql.ToString(), parameters.ToArray()); } stopwatch.Stop(); // 停止监视 TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 double milliseconds = timespan.TotalMilliseconds; // 总毫秒数 Response.Write("执行时间:" + milliseconds + "毫秒"); }
protected void Page_Load(object sender, EventArgs e) { System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 开始监视代 using (DNetContext db = new DNetContext()) { var query = db.GetJoin <Book, Author>((m, n) => m.AuthorID == n.AuthorID && n.IsValid == true, (m, n) => m.Price > 10 && n.IsValid == true, (m, n) => new { BookName = m.BookName + n.AuthorName, n.AuthorName }); var books = db.JoinQuery.LeftJoin <Book, Author>((m, n) => m.AuthorID == n.AuthorID && n.IsValid == true) .Fields <Book, Author>((m, n) => new { BookName = m.BookName + "123", AuthorName = SqlFunctions.Count(n.AuthorName) }) .OrderByAsc <Book>(m => m.BookName) .GroupBy <Book, Author>((m, n) => new { m.BookName, n.AuthorName }) .Where <Book, Author>((m, n) => m.Price > 10 && n.IsValid == true && SubQuery.GetList <Author>(n1 => n1.AuthorID >= 1, n1 => n1.AuthorID).Contains(m.AuthorID)) .GetList <Book>(); var join = db.JoinQueryAlias.LeftJoin <Book, Author>((m, n) => m.AuthorID == n.AuthorID && n.IsValid == true) .InnerJoin <Book, Author>((m1, n) => m1.AuthorID == n.AuthorID && n.IsValid == true) .Fields <Book, Author>((m1, n) => new { AuthorName1 = m1.BookName + n.AuthorName, n }) .OrderByAsc <Book>(m => m.BookName); PageFilter page = new PageFilter { PageIndex = 1, PageSize = 10 }; //分页参数前台传来 var pagesource = join.GetPage <Book>(page); } stopwatch.Stop(); // 停止监视 TimeSpan timespan = stopwatch.Elapsed; // 获取当前实例测量得出的总时间 double milliseconds = timespan.TotalMilliseconds; // 总毫秒数 Response.Write("执行时间:" + milliseconds + "毫秒"); }
public ActionResult <IEnumerable <Pet> > Get([FromQuery] PageFilter pageFilter) { try { if (pageFilter.CurrentPage < 0 || pageFilter.ItemsPerPage < 0) { throw new InvalidDataException("CurrentPage and ItemsPerPage have to be higher than 0"); } if ((pageFilter.CurrentPage - 1 * pageFilter.ItemsPerPage) >= _petService.Count()) { throw new InvalidDataException("Index out of bounds"); } if (_petService.GetFilteredPets(pageFilter) != null) { return(Ok(_petService.GetFilteredPets(pageFilter))); } //if (_petService.GetAllPets() != null) //{ // return Ok(_petService.GetAllPets()); //} return(NotFound()); } catch (System.Exception) { return(StatusCode(500, "Error when looking for list of pets")); } }
/// <summary> /// Stvara polje za prikaz trenutne stranice i unos željene stranice /// </summary> /// <param name="page">Broj trenutne stranice</param> /// <returns></returns> private TagBuilder BuildListItemForCurrentPage(int page) { IUrlHelper urlHelper = urlHelperFactory.GetUrlHelper(ViewContext); TagBuilder input = new TagBuilder("input"); input.Attributes["type"] = "text"; input.Attributes["value"] = page.ToString(); input.Attributes["data-current"] = page.ToString(); input.Attributes["data-min"] = "1"; input.Attributes["data-max"] = PageInfo.TotalPages.ToString(); input.Attributes["data-url"] = urlHelper.Action(PageAction, new { page = -1, sort = PageInfo.Sort, ascending = PageInfo.Ascending, filter = PageFilter?.ToString() }); input.AddCssClass("page-link"); input.AddCssClass("pagebox");//da ga se može pronaći i stilizirati if (!string.IsNullOrWhiteSpace(PageTitle)) { input.Attributes["title"] = PageTitle; } TagBuilder li = new TagBuilder("li"); li.AddCssClass("page-item active"); li.InnerHtml.AppendHtml(input); return(li); }
public PagedResult <StatementModel> GetAllStatements(string filter) { try { _logger.LogInformation($"GetAllStatements:{filter}"); PageFilter obj = null; if (!string.IsNullOrEmpty(filter)) { obj = JsonConvert.DeserializeObject <PageFilter>(filter); } var query = !string.IsNullOrEmpty(obj?.Title) ? _repo.SearchFor(i => i.Title == obj.Title) : _repo.GetAll(); var result = query.Select(i => new StatementModel { Id = i.Id, Img = i.Img, Description = i.Description, Phone = i.Phone, Title = i.Title, Link = "<a href = 'https://localhost:9001/home/details/" + i.Id + "' class= 'btn btn-white'> <i class= 'entypo-plus'></i> ნახვა </a>" } ).AsQueryable().GetPaged(obj.PageIndex, obj.PageSize); return(result); } catch (Exception ex) { _logger.LogError(ex.Message); return(new PagedResult <StatementModel>()); } }
public async Task <List <TEntity> > GetAllAsync(PageFilter pageFilter, IFilter filter = null, params Expression <Func <TEntity, object> >[] includeProperties) { return(await(filter == null ? GetAllAsync(pageFilter, filter, includeProperties) : GetAllAsync(pageFilter, Filter.DynamicFilter <TEntity, IFilter>(filter), includeProperties))); }
public ActionResult Index(string category, PageSizeFilter pageSizeFilter, SortFilter sortFilter, ProducersFilter producerFilter, PageFilter pageFilter, [ModelBinder(typeof(GroupFilterBinder))] GroupFilter groupFilter) { try { var url = ProducerRedirect.GetUrl(Request.Url, category, producerFilter); if (url != string.Empty) { return(RedirectPermanent(url)); } ViewModel = new FilterViewModelBase(category, pageSizeFilter, sortFilter, producerFilter, pageFilter, groupFilter); var categoryObj = categoryRepository.Find(category); if (categoryObj == null) { throw new Exception("Invalid category name."); } ViewModel.CategoryObj = categoryObj; IQueryable <Product> entities = productRepository.GetProductsWithProducerByProductName(category); entities = StartInitialize(entities); EndInitialize(entities); return(View(ViewModel)); } catch (Exception e) { Logger.Error(e); return(RedirectToAction("index", "error", new { statusCode = 404 })); } }
/// <summary> /// Gets a page with result query for delayed execution. /// </summary> /// <param name="query"> /// This should be preferably be a query and not a materialized set so that the pagination /// happens at the store level. /// </param> /// <param name="filter">The page options.</param> public static PageResult <T> GetPage <T>(this IQueryable <T> query, PageFilter filter) { if (query == null) { throw new ArgumentNullException(nameof(query)); } var pageResult = new PageResult <T> { Page = filter.ActualPage, PageSize = filter.ActualPageSize, Results = query }; if (filter?.ActualPage > 0) { // Get the required page pageResult.Results = query .Skip(filter.ActualOffset) .Take(filter.ActualPageSize); } else if (filter != null) { // Invalid negative page number, return 0 results pageResult.Results = query.Take(0); } return(pageResult); }
public List<Pageview> GetByFilter(PageFilter filter = null) { //Contract.Requires(!string.IsNullOrEmpty(f.FilterField), "Specify filter filed name"); Contract.Requires(filter == null || filter.CountPerPage > 0, "Specify filter filed name"); Contract.Requires(filter.SortType == SortOrder.None || !string.IsNullOrEmpty(filter.SortField), "Specify order filed name"); var query = _pageviewRepository.GetAll(); if (filter != null) { foreach(var f in filter.Filters) { query = query.CustomWhere(f.FilterField, f.FilterType.ToString(), f.Term); } if (filter.SortType != SortOrder.None) { query = query.OrderBy(string.Format("{0} {1}", filter.SortField, filter.SortType == SortOrder.Desc ? "descending" : string.Empty)); } else { //Skip requiresordering query = query.OrderBy(q => q.ID); } query = query.Skip(filter.Page * filter.CountPerPage).Take(filter.CountPerPage); } return query.ToList(); }
public static Query Limit(this Query query, PageFilter filter) { query.Skip(filter.Skip); query.Take(filter.Take); return(query); }
private void LoadFilters() { var datePeriods = DateFilter.GetDateFiltersSelectList(); // var datePeriodsJs = DateFilter.GetDateFiltersSelectList(); ViewData["DataFilterValues"] = new SelectList(datePeriods, "Value", "Text"); var pageFilterSize = PageFilter.GetPageSizeFiltersSelectList(); ViewData["PageFilterSize"] = new SelectList(pageFilterSize, "Value", "Text"); var dbCompanies = _context.Companies.OrderBy(p => p.Code).AsNoTracking(); List <SelectListItem> companiesList = new List <SelectListItem>(); companiesList.Add(new SelectListItem() { Value = 0.ToString(), Text = "{All Companies}" }); foreach (var company in dbCompanies) { companiesList.Add(new SelectListItem() { Value = company.Id.ToString(), Text = company.Code }); } ViewData["CompanyFilter"] = new SelectList(companiesList, "Value", "Text"); }
public void CanFilterPagesWithStaticMethod() { ItemList list = CreateList(); PageFilter.FilterPages(list); Assert.AreEqual(2, list.Count); }
/// <summary> /// 获取分页数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pageFilter"></param> /// <returns></returns> public PageDataSource <T> GetPage <T>(PageFilter pageFilter) where T : class, new() { StringBuilder selectSql = new StringBuilder(); List <DbParameter> parms = new List <DbParameter>(); if (pageFilter is PageFilter <T> ) { GetSQLByLambda(selectSql, parms, (Expression <Func <T, bool> >)((PageFilter <T>)pageFilter).WhereExpression); } else { GetSQLByLambda <T>(selectSql, parms, null); } PageDataSource <T> dataSource = new PageDataSource <T>(); int recordCount, pageCount, pageIndex; using (var reader = DataBase.ExecutePageReader(selectSql.ToString(), pageFilter.OrderText, pageFilter.PageIndex, pageFilter.PageSize, out recordCount, out pageCount, out pageIndex, parms.ToArray())) { dataSource.RecordCount = recordCount; dataSource.PageCount = pageCount; dataSource.PageIndex = pageIndex; dataSource.PageSize = pageFilter.PageSize; dataSource.DataSource = new List <T>(); while (reader.Read()) { T entityWhile = new T(); SetEntityMembers <T>(reader, entityWhile); dataSource.DataSource.Add(entityWhile); } return(dataSource); } }
public BusinessUsersTest() { _moqDataUsers = new Mock <IDataUsers>(); _moqRepoBase = new Mock <IRepoBase>(); var mappingConfig = new MapperConfiguration(mc => { mc.CreateMap <EntityUser, User>(); mc.CreateMap <User, EntityUser>(); }); _imapper = mappingConfig.CreateMapper(); _entityUser = new EntityUser { Username = "******", Password = "******" }; _user = new User { Username = "******", Password = "******", NewPassword = "******" }; _pageFilter = new PageFilter { PageNo = 1, ItemsPerPage = 1, }; }
/// <summary> /// 查询分页数据 /// 根据SQL查询 不设置排序则为默认排序 不需要设置LambdaExpression /// </summary> /// <typeparam name="TObject"></typeparam> /// <param name="sql"></param> /// <param name="pageFilter"></param> /// <returns></returns> public PageDataSource <TObject> GetPage <TObject>(string sql, PageFilter pageFilter) { using (DbContext) { return(DbContext.GetPage <TObject>(sql, pageFilter)); } }
/// <summary> /// 查询分页数据 /// 根据SQL查询 不设置排序则为默认排序 不需要设置LambdaExpression /// </summary> /// <typeparam name="TObject"></typeparam> /// <param name="sql"></param> /// <param name="pageFilter"></param> /// <param name="cmdParms"></param> /// <returns></returns> public PageDataSource <TObject> GetPage <TObject>(string sql, PageFilter pageFilter, params DbParameter[] cmdParms) { using (DbContext) { return(DbContext.GetPage <TObject>(sql, pageFilter, cmdParms)); } }
private void LoadFilters() { var dbTransactorTypes = _context.TransactorTypes.OrderBy(p => p.Code).AsNoTracking(); List <SelectListItem> transactorTypes = new List <SelectListItem>(); transactorTypes.Add(new SelectListItem() { Value = 0.ToString(), Text = "{All Types}" }); foreach (var dbTransactorType in dbTransactorTypes) { transactorTypes.Add(new SelectListItem() { Value = dbTransactorType.Id.ToString(), Text = dbTransactorType.Code }); } ViewData["TransactorTypeId"] = new SelectList(transactorTypes, "Value", "Text"); var pageFilterSize = PageFilter.GetPageSizeFiltersSelectList(); ViewData["PageFilterSize"] = new SelectList(pageFilterSize, "Value", "Text"); //var dbCompanies = _context.Companies.OrderBy(p => p.Code).AsNoTracking(); //List<SelectListItem> companiesList = new List<SelectListItem>(); //companiesList.Add(new SelectListItem() { Value = 0.ToString(), Text = "{All Companies}" }); //foreach (var company in dbCompanies) //{ // companiesList.Add(new SelectListItem() { Value = company.Id.ToString(), Text = company.Code }); //} var companiesList = FiltersHelper.GetCompaniesFilterList(_context); ViewData["CompanyFilter"] = new SelectList(companiesList, "Value", "Text"); }
/// <summary> /// 获取分页数据 /// </summary> /// <param name="pageFilter"></param> /// <returns></returns> public PageDataSource <T> GetPage(PageFilter pageFilter) { using (DbContext) { return(DbContext.GetPage <T>(pageFilter)); } }
public async Task <RequestResult <PagedList <Fibonacci> > > Read(PageFilter pageFilter, CancellationToken cancellationToken) { var requestResult = new RequestResult <PagedList <Fibonacci> >(); if (pageFilter.ItemsPerPage > 100) { pageFilter.ItemsPerPage = 100; requestResult.Errors.Add("Cannot return more than 100 records at a time"); } var queryResult = await _iDataFibonaccis.Read(pageFilter.Offset, pageFilter.ItemsPerPage); var entityFibonaccis = queryResult.Item1; var pagedFibonaccis = new PagedList <Fibonacci> { Items = _iMapper.Map <List <Fibonacci> >(entityFibonaccis), ItemsPerPage = pageFilter.ItemsPerPage, NumberOfItems = queryResult.Item2, PageNo = pageFilter.PageNo }; requestResult.Model = pagedFibonaccis; return(requestResult); }
public List <D> PageQuery <D>(Func <IQueryable <T>, IQueryable <T> > func, PageFilter pageInfo, Expression <Func <T, D> > selector) { IQueryable <T> queryable = func(this.TDbSet.Where <T>(ft => ft.DEL_FLAG == 0)); //获取满足条件的数据数量 pageInfo.TotalPageCount = queryable.Count(); //排序 if (!string.IsNullOrEmpty(pageInfo.SortOrder)) { if (pageInfo.SortOrder.ToLower() == "desc") { queryable = queryable.OrderByDescendingProp(pageInfo.SortName); } else { queryable = queryable.OrderByProp(pageInfo.SortName); } } //分页 queryable = queryable.Skip((pageInfo.PageIndex - 1) * pageInfo.PageSize).Take(pageInfo.PageSize); return(queryable.Select(selector).ToList()); }
public async Task <ClinicResponse> GetClinicByGuid(string guid, PageFilter filter) { ClinicResponse _response = new ClinicResponse(); try { List <ClinicsEntity> results = await _context.Clinics.Where(x => x.IsDeleted == false).Where(x => x.ClinicGuid == guid).OrderByDynamic(filter.Column, filter.Descending).Skip(filter.Index * filter.Count).Take(filter.Count).ToListAsync(); _response.Code = "E000"; _response.Message = _localizer["success"]; _response.DataCount = await _context.Clinics.Where(x => x.IsDeleted == false).Where(x => x.ClinicGuid == guid).CountAsync(); _response.ResponseDate = DateTime.Now.ToUniversalTime(); _response.Results.AddRange(results); } catch (Exception ex) { _response.Code = "E999"; _response.Message = ex.Message; _response.DataCount = 0; _response.ResponseDate = DateTime.Now.ToUniversalTime(); _response.Results = null; } return(_response); }
public async Task <IActionResult> Get([FromQuery] PageFilter pageFilter, [FromQuery] OfferViewModelFilter filter) { Expression <Func <Offer, bool> > offerFilter = OfferFilter.ConvertTo(filter); offerFilter = offerFilter.AndAlso(x => x.Active == true); PagedFilter <Offer> pagedFilter = new PagedFilter <Offer>(pageFilter.Page, pageFilter.Limit, offerFilter); Expression <Func <Offer, object> >[] includes = new Expression <Func <Offer, object> >[] { x => x.Employer, x => x.OfferType }; PagedResult <Offer> offers = await _offerService.Get(pagedFilter, include : includes); IEnumerable <OfferViewModel> offerViewModel = OfferViewModel.From(offers.Data); PagedResult <OfferViewModel> queryResult = new PagedResult <OfferViewModel>(offerViewModel, offers.Page, offers.Limit, offers.ElementsCount); return(Ok(queryResult)); }
private void context_ReleaseRequestState(object sender, EventArgs e) { if (!Inited) return; HttpResponse response = HttpContext.Current.Response; RequestState rs = EnsureRequestState(); rs.RequestContent = string.Empty; System.Text.StringBuilder sb = new System.Text.StringBuilder(); rs.RequestContent = GetRequestString(HttpContext.Current); //if (response.ContentType == "text/html") //{ PageFilter pf = new PageFilter(response.Filter); response.Filter = pf; //} }