public async static Task<PagedList<Connection>> FindAllAsync(string type, string query = null, IEnumerable<string> fields = null, int page = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending) { var request = new FindAllConnectionsRequest() { Type = type, Query = query, PageNumber = page, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var connections = new PagedList<Connection>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FindAllAsync(type, query, fields, page + skip + 1, pageSize) }; connections.AddRange(response.Connections); return connections; }
public async Task <PagedList <Model> > GetModelsAsync(string vendor, string number, int heightStart, int heightEnd, int networkRangeStart, int networkRangeEnd, int powerRangeStart, int powerRangeEnd, int memoryRangeStart, int memoryRangeEnd, string sortBy, string isDesc, int page = 1, int pageSize = 10) { var pagedList = new PagedList <Model>(); Expression <Func <Model, bool> > vendorCondition = x => (x.Vendor.Contains(vendor)); Expression <Func <Model, bool> > numberCondition = x => (x.ModelNumber.Contains(number)); var models = await Sort(vendor, number, heightStart, heightEnd, networkRangeStart, networkRangeEnd, powerRangeStart, powerRangeEnd, memoryRangeStart, memoryRangeEnd, sortBy, isDesc, page, pageSize); pagedList.AddRange(models); pagedList.TotalCount = await _dbContext.Models .WhereIf(!string.IsNullOrEmpty(vendor), vendorCondition) .WhereIf(!string.IsNullOrEmpty(number), numberCondition) .Where(x => x.Height >= heightStart && x.Height <= heightEnd && x.EthernetPorts >= networkRangeStart && x.EthernetPorts <= networkRangeEnd && x.PowerPorts >= powerRangeStart && x.PowerPorts <= powerRangeEnd && x.Memory >= memoryRangeStart && x.Memory <= memoryRangeEnd) .CountAsync(); pagedList.PageSize = pageSize; pagedList.CurrentPage = page; return(pagedList); }
public async Task <PagedList <SubjectModel> > GetSubjectsAsync(Guid groupId, Guid semesterId, ListOptions listOptions) { var query = Context.SelectSubjectByGroupAndSemester(groupId, semesterId); //var query = from subject in Context.Subjects // join gss in Context.GroupSemesterSubjects on subject.Id equals gss.SubjectId // join gs in Context.GroupSemesters on gss.GroupSemesterId equals gs.Id // where gs.GroupId == groupId && gs.SemesterId == semesterId // orderby subject.Name // select new Subject {Id = gss.Id, Name = subject.Name}; var result = new PagedList <SubjectModel>(); //if (listOptions != null) //{ // query = query.Skip(listOptions.Offset).Take(listOptions.PageSize); // result.Page = listOptions.Page; // result.PageSize = listOptions.PageSize; //} var subjects = await query.ToListAsync(); result.AddRange(Mapper.Map <IEnumerable <Subject>, IEnumerable <SubjectModel> >(subjects)); return(result); }
public async Task <PagedList <Datacenter> > GetOfflineDatacentersAsync(string search, int page = 1, int pageSize = 10) { var pagedList = new PagedList <Datacenter>(); //if Expression <Func <Datacenter, bool> > searchCondition = x => (x.Name.Contains(search) || x.Description.Contains(search)); var datacenters = await _dbContext.Datacenters //.Include(dc => dc.Racks) //.ThenInclude(rack => rack.Pdus) //.ThenInclude(pdu => pdu.Ports) .Where(x => x.IsOffline == true) .WhereIf(!string.IsNullOrEmpty(search), searchCondition) .PageBy(x => x.Name, page, pageSize) //.AsNoTracking() .ToListAsync(); pagedList.AddRange(datacenters); pagedList.TotalCount = await _dbContext.Datacenters .WhereIf(!string.IsNullOrEmpty(search), searchCondition) .CountAsync(); pagedList.PageSize = pageSize; pagedList.CurrentPage = page; return(pagedList); }
public async static Task<PagedList<Article>> FindAllAsync(string type, string query = null, IEnumerable<string> fields = null, int page = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending ) { var service = ObjectFactory.Build<IArticleService>(); var request = new FindAllArticleRequest() { Type = type, Query = query, PageNumber = page, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; var response = await service.FindAllAsync(request); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var articles = new PagedList<Article>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FindAllAsync(type, query, fields, page+skip+1, pageSize) }; articles.AddRange(response.Articles); return articles; }
public async Task <PagedList <SaleApiModel> > GetDailySales() { var query = await _db.Sales.AsNoTracking() .Include(s => s.ItemsSold) .Where(s => s.SaleDate == DateTimeOffset.UtcNow.Date) .Select(s => new SaleApiModel { GrandTotal = s.GrandTotal, SaleDate = s.SaleDate, TypeOfPayment = s.ModeOfPayment, TypeOfSale = s.TypeOfSale, SaleId = s.Id, ProductsSold = s.ItemsSold.Select(x => new ProductSoldModel { Price = x.RetailPrice, ProductId = x.Id, Quantity = x.Quantity }).ToList() }).ToListAsync().ConfigureAwait(false); var list = new PagedList <SaleApiModel>(); list.AddRange(query); return(list); }
public async Task <PagedList <MessageModel> > GetChildMessagesAsync(Guid parentMessageId, ListOptions listOptions) { var query = Context.Messages.Include(m => m.Author).Include(m => m.Files).AsQueryable(); var list = new PagedList <MessageModel>(); list.TotalItemCount = await Context.Messages.CountAsync(m => m.ParentMessageId == parentMessageId); if (list.TotalItemCount == 0) { return(list); } if (listOptions != null) { list.Page = listOptions.Page; list.PageSize = listOptions.PageSize; query = query.OrderByDescending(t => t.CreationDate).Skip(listOptions.Offset).Take(listOptions.PageSize); } query = query.Where(m => m.ParentMessageId == parentMessageId); var messages = await query.ToArrayAsync(); list.AddRange(Mapper.Map <IEnumerable <Message>, IEnumerable <MessageModel> >(messages)); return(list); }
/// <summary> /// Return an object that contains paged result for a query /// </summary> /// <param name="page">Page</param> /// <param name="limit">Limit per page</param> /// <param name="query">Query to apply</param> /// <returns></returns> public async Task <PagedList <TDocument> > Get(int page, int limit, IMongoQueryable <TDocument> query) { // Define a query query ??= AsQueryable(); // Apply main filters query = query.Where(p => !p.Deleted); // // Get count var total = await query.CountAsync(); // Create result var result = new PagedList <TDocument> { TotalCount = total, PageIndex = page, PageSize = limit }; // Return result if (total == 0) { return(result); } query = limit == 0 ? query : query.Skip((page - 1) * limit).Take(limit); result.AddRange(await query.ToListAsync()); return(result); }
public static async Task <PagedList <TEntity> > ToPagedListAsync <TEntity>( this IQueryable <TEntity> source, IPagingParams pagingParams ) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (pagingParams == null) { throw new ArgumentNullException(nameof(pagingParams)); } if (pagingParams.PageNumber < 0 || pagingParams.PageSize < 0) { throw new ArgumentException("Page number or page size cannot be less than zero!"); } PagedList <TEntity> pagedList = new PagedList <TEntity>(pagingParams, await source.CountAsync()); var items = await source.Skip((pagingParams.PageNumber - 1) *pagingParams.PageSize) .Take(pagingParams.PageSize) .ToListAsync(); pagedList.AddRange(items); return(pagedList); }
/// <summary> /// 获取分页 /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="order"></param> /// <param name="asc"></param> /// <returns></returns> public PagedList <T> GetPagedList(int pageIndex, int pageSize, string order, bool asc) { var total = this.Count(); var list = this.OrderBy(new OrderByOperation(order, asc ? OrderByOperater.ASC : OrderByOperater.DESC)).Page(pageIndex, pageSize).ToList <T>(); var pagedlist = new PagedList <T>(pageIndex, pageSize, total); pagedlist.AddRange(list); return(pagedlist); }
public async Task <PagedList <Asset> > GetAssetsAsync(Guid?datacenterId, string vendor, string number, string hostname, string rackStart, string rackEnd, string sortBy, string isDesc, int page, int pageSize, bool isOffline) { var pagedList = new PagedList <Asset>(); Expression <Func <Asset, bool> > hostnameCondition = x => (x.Hostname.Contains(hostname)); Expression <Func <Asset, bool> > vendorCondition = x => (x.Model.Vendor.Contains(vendor)); Expression <Func <Asset, bool> > numberCondition = x => (x.Model.ModelNumber.Contains(number)); Expression <Func <Asset, bool> > bladeCondition = asset => (!asset.Model.MountType.Contains("blade")); Expression <Func <Asset, bool> > otherBladeCondition = asset => ((asset.ChassisId == null || asset.ChassisId == Guid.Empty)); var assets = await _dbContext.Assets .Include(asset => asset.Rack) .Where(x => x.Rack.Datacenter.IsOffline == isOffline) //.ThenInclude(rack => rack.Pdus) //.ThenInclude(pdu => pdu.Ports) .WhereIf(datacenterId != null, x => x.Rack.Datacenter.Id == datacenterId) .WhereIf(!string.IsNullOrEmpty(hostname), hostnameCondition) .WhereIf(!string.IsNullOrEmpty(vendor), vendorCondition) .WhereIf(!string.IsNullOrEmpty(number), numberCondition) //If we don't want the blades to appear on the table.... but how to add in the search requirements? .WhereIf(!isOffline, bladeCondition) .WhereIf(isOffline, otherBladeCondition) .Where(x => x.RackId != null && x.RackId != Guid.Empty && String.Compare(x.Rack.Row.ToUpper(), rackStart[0].ToString()) >= 0 && String.Compare(x.Rack.Row.ToUpper(), rackEnd[0].ToString()) <= 0 && x.Rack.Column >= int.Parse(rackStart.Substring(1)) && x.Rack.Column <= int.Parse(rackEnd.Substring(1))) .PageBy(x => x.Hostname, page, pageSize) .ToListAsync(); assets = await UpdateBlades(assets); assets = Sort(assets, sortBy, isDesc); pagedList.AddRange(assets); pagedList.TotalCount = await _dbContext.Assets .WhereIf(datacenterId != null, x => x.Rack.Datacenter.Id == datacenterId) .WhereIf(!string.IsNullOrEmpty(hostname), hostnameCondition) .WhereIf(!string.IsNullOrEmpty(vendor), vendorCondition) .WhereIf(!string.IsNullOrEmpty(number), numberCondition) .Where(asset => !asset.Model.MountType.Contains("blade")) .Where(x => x.RackId != null && x.RackId != Guid.Empty && String.Compare(x.Rack.Row.ToUpper(), rackStart[0].ToString()) >= 0 && String.Compare(x.Rack.Row.ToUpper(), rackEnd[0].ToString()) <= 0 && x.Rack.Column >= int.Parse(rackStart.Substring(1)) && x.Rack.Column <= int.Parse(rackEnd.Substring(1))) .CountAsync(); pagedList.PageSize = pageSize; pagedList.CurrentPage = page; return(pagedList); }
public async static Task<PagedList<Device>> FindAllAsync(string query = null, IEnumerable<string> fields = null, int page = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending) { var articles = await Articles.FindAllAsync("device", query, fields, page, pageSize, orderBy, sortOrder); var devices = articles.Select(x => new Device(x)); var list = new PagedList<Device>() { PageNumber = articles.PageNumber, PageSize = articles.PageSize, TotalRecords = articles.TotalRecords, GetNextPage = async skip => await FindAllAsync(query, fields, page + skip + 1, pageSize, orderBy, sortOrder) }; list.AddRange(devices); return list; }
/// <summary> /// Finds a paginated list of APDevices for the given type and search criteria. /// </summary> /// <param name="freeTextExpression">Free text search expression over all fields of the given type.</param> /// <param name="query">The search query</param> /// <param name="fields">The device specific fields to be retrieved.</param> /// <param name="pageNumber">The page number.</param> /// <param name="pageSize">The page size.</param> /// <param name="orderBy">The field on which to sort.</param> /// <param name="sortOrder">Sort order - Ascending or Descending.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> /// <returns>A paginated list of APDevice objects for the given search criteria.</returns> public async static Task<PagedList<APDevice>> FindAllAsync(string freeTextExpression, IQuery query = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null) { var objects = await APObjects.FindAllAsync("device", freeTextExpression, query, fields, pageNumber, pageSize, orderBy, sortOrder, options); var devices = objects.Select(x => x as APDevice); var list = new PagedList<APDevice>() { PageNumber = objects.PageNumber, PageSize = objects.PageSize, TotalRecords = objects.TotalRecords, GetNextPage = async skip => await FindAllAsync(freeTextExpression, query, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options) }; list.AddRange(devices); return list; }
public async Task <PagedList <Rack> > GetRacksAsync(Guid?datacenterId, string sortBy, string isDesc, int page = 1, int pageSize = 10) { var pagedList = new PagedList <Rack>(); var racks = await Sort(datacenterId, sortBy, isDesc, page, pageSize); pagedList.AddRange(racks); pagedList.TotalCount = await _dbContext.Racks .WhereIf(datacenterId != null, x => x.Datacenter.Id == datacenterId) .CountAsync(); pagedList.PageSize = pageSize; pagedList.CurrentPage = page; return(pagedList); }
public async Task <PagedList <ThemeModel> > GetUserThemesAsync(Guid userId, ListOptions listOptions = null) { var themes = Context.Themes.Include(t => t.Author).AsQueryable(); var result = new PagedList <ThemeModel>(); if (listOptions != null) { themes = themes.OrderBy(t => t.CreationDate).Skip(listOptions.Offset).Take(listOptions.PageSize); result.Page = listOptions.Page; result.PageSize = listOptions.PageSize; } var themeList = await themes.Where(t => t.AuthorId == userId).ToListAsync(); result.AddRange(Mapper.Map <IEnumerable <Theme>, IEnumerable <ThemeModel> >(themeList)); return(result); }
public static PagedList <TEntity> ToPagedList <TEntity>(this IQueryable <TEntity> queryable, int page, int pageSize) where TEntity : class { int total = queryable.Count(); if (page < 1) { page = 1; } if (pageSize < 1) { pageSize = 1; } var models = queryable.Skip((page - 1) * pageSize).Take(pageSize).ToList(); PagedList <TEntity> list = new PagedList <TEntity>(page, pageSize, total); list.AddRange(models); return(list); }
public static async Task <PagedList <T> > ToPagedAsync <T>(this IQueryable <T> queryable, int page, int limit) where T : class { var paged = new PagedList <T> { TotalCount = await queryable.CountAsync(), PageIndex = page, PageSize = limit }; if (paged.TotalCount == 0) { return(paged); } paged.AddRange(await queryable.Skip((page - 1) * limit).Take(limit).ToListAsync()); return(paged); }
public async Task <PagedList <ThemeModel> > GetThemesAsync(ThemeFilter filter, ListOptions listOptions) { var themes = Context.Themes.Include(t => t.Author).AsQueryable(); if (filter != null) { if (filter.AuthorId.HasValue) { themes = themes.Where(t => t.AuthorId == filter.AuthorId); } if (filter.SubjectId.HasValue) { themes = themes.Where(t => t.SubjectId == filter.SubjectId); } if (filter.CreateDateAfter.HasValue) { themes = themes.Where(t => t.CreationDate >= filter.CreateDateAfter); } if (filter.CreateDateBefore.HasValue) { themes = themes.Where(t => t.CreationDate <= filter.CreateDateBefore); } if (!string.IsNullOrEmpty(filter.SearchString)) { themes = themes.Where( t => t.Title.Contains(filter.SearchString)); } } var result = new PagedList <ThemeModel>(); if (listOptions != null) { themes = themes.OrderBy(t => t.CreationDate).Skip(listOptions.Offset).Take(listOptions.PageSize); result.Page = listOptions.Page; result.PageSize = listOptions.PageSize; } var themeList = await themes.ToListAsync(); result.AddRange(Mapper.Map <IEnumerable <Theme>, IEnumerable <ThemeModel> >(themeList)); return(result); }
public async Task <PagedList <ChangePlan> > GetChangePlansAsync(Guid?createdById, int page = 1, int pageSize = 10) { var pagedList = new PagedList <ChangePlan>(); var changePlans = await _dbContext.ChangePlans .Where(x => x.CreatedById == createdById) .PageBy(x => x.Id, page, pageSize) .AsNoTracking() .ToListAsync(); pagedList.AddRange(changePlans); pagedList.TotalCount = await _dbContext.ChangePlans .Where(x => x.Id == createdById) .CountAsync(); pagedList.PageSize = pageSize; pagedList.CurrentPage = page; return(pagedList); }
public async Task <PagedList <DecommissionedAsset> > GetDecommissionedAssetsAsync(string datacenterName, string generalSearch, string decommissioner, string dateStart, string dateEnd, string rackStart, string rackEnd, string sortBy, string isDesc, int page, int pageSize) { var pagedList = new PagedList <DecommissionedAsset>(); Expression <Func <DecommissionedAsset, bool> > hostnameCondition = x => (x.Hostname.Contains(generalSearch) || x.ModelName.Contains(generalSearch) || x.ModelNumber.Contains(generalSearch)); Expression <Func <DecommissionedAsset, bool> > decommissionerCondition = x => (x.Decommissioner.Contains(decommissioner)); Expression <Func <DecommissionedAsset, bool> > startDateCondition = x => (x.DateDecommissioned >= DateTime.Parse(dateStart)); Expression <Func <DecommissionedAsset, bool> > endDateCondition = x => (x.DateDecommissioned <= DateTime.Parse(dateEnd)); Expression <Func <DecommissionedAsset, bool> > datacenterCondition = x => (x.Datacenter.Contains(datacenterName)); var assets = await _dbContext.DecommissionedAssets .WhereIf(!string.IsNullOrEmpty(generalSearch), hostnameCondition) .WhereIf(!string.IsNullOrEmpty(decommissioner), decommissionerCondition) .WhereIf(!string.IsNullOrEmpty(dateStart), startDateCondition) .WhereIf(!string.IsNullOrEmpty(dateEnd), endDateCondition) .WhereIf(!string.IsNullOrEmpty(datacenterName), datacenterCondition) //.Where(x => !x.Data.Contains("\"MountType\":\"blade")) .PageBy(x => x.Id, page, pageSize) .ToListAsync(); assets = assets.Where(x => String.Compare(x.Rack[0].ToString().ToUpper(), rackStart[0].ToString()) >= 0 && String.Compare(x.Rack[0].ToString().ToUpper(), rackEnd[0].ToString()) <= 0 && int.Parse(x.Rack.Substring(1)) >= int.Parse(rackStart.Substring(1)) && int.Parse(x.Rack.Substring(1)) <= int.Parse(rackEnd.Substring(1))) .ToList(); assets = SortDecommissionedAsset(assets, sortBy, isDesc); pagedList.AddRange(assets); pagedList.TotalCount = await _dbContext.DecommissionedAssets .WhereIf(!string.IsNullOrEmpty(datacenterName), datacenterCondition) .WhereIf(!string.IsNullOrEmpty(generalSearch), hostnameCondition) .WhereIf(!string.IsNullOrEmpty(decommissioner), decommissionerCondition) .WhereIf(!string.IsNullOrEmpty(dateStart), startDateCondition) .WhereIf(!string.IsNullOrEmpty(dateEnd), endDateCondition) .WhereIf(!string.IsNullOrEmpty(datacenterName), datacenterCondition) .CountAsync(); pagedList.PageSize = pageSize; pagedList.CurrentPage = page; return(pagedList); }
public static async Task <PagedList <T> > ToPagedAsync <T>(this IQueryable <T> queryable) where T : class { var paged = new PagedList <T> { TotalCount = await queryable.CountAsync(), PageIndex = 1 }; paged.PageSize = paged.TotalCount; if (paged.TotalCount == 0) { return(paged); } paged.AddRange(await queryable.ToListAsync()); return(paged); }
/// <summary> /// 根据条件,返回分页的文档集合 /// </summary> /// <param name="predicate"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public virtual async Task <IPaged <T> > PagedSelectAsync(Expression <Func <T, bool> > predicate, int pageIndex, int pageSize) { if (pageIndex < 1) { pageIndex = 1; } if (pageSize < 1) { pageSize = 20; } var query = Collection.AsQueryable(); if (predicate != null) { query = query.Where(predicate); } var recordTotal = query.Count(); var pageTotal = recordTotal / pageSize; if (recordTotal % pageSize > 0) { pageTotal++; } if (pageIndex > 1) { query = query.Skip((pageIndex - 1) * pageSize); } var records = await query.Take(pageSize).ToListAsync(); var pagedList = new PagedList <T>() { PageTotal = pageTotal, RecordTotal = recordTotal, Index = pageIndex, Size = pageSize }; pagedList.AddRange(records); return(pagedList); }
public static PagedList <TModel> ToPagedList <TEntity, TModel>(this IQueryable <TEntity> queryable, int page, int pageSize, Func <TEntity, TModel> mapTo) where TEntity : class where TModel : class { int total = queryable.Count(); if (page < 1) { page = 1; } if (pageSize < 1) { pageSize = 1; } var models = queryable.Skip((page - 1) * pageSize).Take(pageSize).ToList().Select(x => mapTo(x)); PagedList <TModel> list = new PagedList <TModel>(page, pageSize, total); list.AddRange(models); return(list); }
public static async Task<PagedList<ListItem>> GetListItemsAsync(string listName, int page = 1, int pageSize = 20) { var request = new GetListContentRequest { Name = listName, PageNumber = page, PageSize = pageSize }; var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var list = new PagedList<ListItem>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await GetListItemsAsync(listName, pageSize, page + skip + 1) }; list.AddRange(response.Items); return list; }
public async Task <ActionResult <PagedList <ProductApiModel> > > GetProducts() { var result = await _context.Products.AsNoTracking() .Include(p => p.ProductShelf) .Select(p => new ProductApiModel { CostPrice = p.CostPrice, Name = p.Name, ProductId = p.Id, ShelfId = p.ShelfId, Quantity = p.Quantity, RetailPrice = p.RetailPrice, SupplyDate = p.SupplyDate, UnitMeasure = p.UnitMeasure }).OrderByDescending(p => p.SupplyDate) .ToListAsync().ConfigureAwait(false); var list = new PagedList <ProductApiModel>(); list.AddRange(result); return(Ok(list)); }
/// <summary> /// 根据条件,返回分页的文档集合 /// </summary> /// <param name="filter"></param> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <returns></returns> public virtual async Task <IPaged <T> > PagedSelectAsync(FilterDefinition <T> filter, int pageIndex, int pageSize) { if (pageIndex < 1) { pageIndex = 1; } if (pageSize < 1) { pageSize = 20; } var fluent = Collection.Find(filter); var recordTotal = fluent.Count(); var pageTotal = recordTotal / pageSize; if (recordTotal % pageSize > 0) { pageTotal++; } if (pageIndex > 1) { fluent = fluent.Skip((pageIndex - 1) * pageSize); } var records = await fluent.Limit(pageSize).ToListAsync(); var pagedList = new PagedList <T>() { PageTotal = (int)pageTotal, RecordTotal = (int)recordTotal, Index = pageIndex, Size = pageSize }; pagedList.AddRange(records); return(pagedList); }
/// <summary> /// Gets a paged list of all matching users. /// </summary> /// <param name="query">Filter query to filter out a specific list of users. </param> /// <param name="fields">List of fields to return</param> /// <param name="pageNumber">Page number</param> /// <param name="pageSize">Page size</param> /// <param name="orderBy">The field on which to sort.</param> /// <param name="sortOrder">Sort order - Ascending or Descending.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> /// <returns>A paged list of users.</returns> public async static Task<PagedList<APUser>> FindAllAsync(IQuery query = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null) { query = query ?? Query.None; var request = new FindAllUsersRequest() { Query = query.AsString().Escape(), PageNumber = pageNumber, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; if (fields != null) request.Fields.AddRange(fields); ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var users = new PagedList<APUser>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FindAllAsync(query, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options) }; users.AddRange(response.Users); return users; }
public PagedList<Post> GetBlogPosts(int pageNumber, int pageSize, PostsSortEnum sort = PostsSortEnum.Newest, Tag tag = null, Category category = null) { var queryActions = new List<Action<IQuery>>(); // base where query var where = "where VersionOf.ID Is Null and ( ci.class = :class And ci.Parent.ID = :parentId)"; queryActions.Add(q => { q.SetCacheable(true); q.SetParameter("class", "Post"); q.SetParameter("parentId", ID); }); // are we filtering by a tag? if (tag != null) { where += " and (ci in (select cd.EnclosingItem from ContentDetail cd where cd.LinkedItem in (:tagItem) AND cd.Name = :tagDetailName))"; queryActions.Add(q => { q.SetParameter("tagItem", tag); q.SetParameter("tagDetailName", "BlogTags"); }); } // are we filtering by a category? if (category != null) { where += " and (ci in (select cd.EnclosingItem from ContentDetail cd where cd.LinkedItem in (:categoryItem) AND cd.Name = :categoryDetailName))"; queryActions.Add(q => { q.SetParameter("categoryItem", category); q.SetParameter("categoryDetailName", "BlogCategories"); }); } // get the posts paged var query = Context.Current.Resolve<ISessionProvider>().OpenSession.Session.CreateQuery("select ci from ContentItem ci " + where + " order by (select MAX(DateTimeValue) from ContentDetail cd where cd.EnclosingItem = ci and cd.Name = 'postCreatedDate') desc"); query.SetFirstResult((pageNumber - 1) * pageSize); query.SetMaxResults(pageSize); Array.ForEach(queryActions.ToArray(), a => a(query)); var posts = query.List<Post>(); // get the total number of posts query = Context.Current.Resolve<ISessionProvider>().OpenSession.Session.CreateQuery("select count(*) from ContentItem ci " + where); Array.ForEach(queryActions.ToArray(), a => a(query)); var total = Convert.ToInt32(query.List()[0]); // return the paged list var pagedList = new PagedList<Post>(); pagedList.AddRange(posts); pagedList.PageNumber = pageNumber; pagedList.PageSize = pageSize; pagedList.TotalCount = total; pagedList.TotalPages = (int)Math.Ceiling((decimal)total / pageSize); return pagedList; }
/// <summary> /// Gets a paginated list of APConnections for the current object of the given connection type. /// </summary> /// <param name="connectionType">The type (relation name) of the connection.</param> /// <param name="query">Search query to further filter the list of connection objects.</param> /// <param name="label">Label of the endpoint to be queried. This is mandatory when the connection type being queried has endpoints with the same type but different labels.</param> /// <param name="fields">The fields to be returned for the matching objects.</param> /// <param name="pageNumber">The page number.</param> /// <param name="pageSize">The page size.</param> /// <param name="orderBy">The field on which to sort the results.</param> /// <param name="sortOrder">The sort order - Ascending or Descending.</param> /// <returns>A paginated list of APConnection objects.</returns> public async Task<PagedList<APConnection>> GetConnectionsAsync(string connectionType, string query = null, string label = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null) { var request = new FindConnectedObjectsRequest { Relation = connectionType, ObjectId = this.Id, Object = this, Query = query, Label = label, Type = this.Type, ReturnEdge = true, PageNumber = pageNumber, PageSize = pageSize, SortOrder = sortOrder, OrderBy = orderBy }; if (fields != null) request.Fields.AddRange(fields); ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var list = new PagedList<APConnection> { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await GetConnectionsAsync(connectionType, query, null, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options) }; list.AddRange(response.Nodes.Select(n => n.Connection)); return list; }
/// <summary> /// 二手房的联络列表 /// </summary> /// <param name="queryDto"></param> /// <returns></returns> public ContactByResaleHouseDto SearchByResaleHouseId(ContactByResaleHouseQueryDto queryDto) { var userQuery = db.GetUserQuery(); var query = from contact in db.MlsContactRecordLogQuery join user in userQuery on contact.UserId equals user.UserId where contact.ResourcesId == queryDto.HouseId && contact.Type == (int)EnumHosueCommonType.ResaleHouse orderby contact.CreateTime descending select new ResaleHouseContactListDto { UserInfo = user, OperationType = (ContactEnum)contact.OperationType, CreateTime = contact.CreateTime, //HowTimes = 10, Id = contact.Id }; PagedList <ResaleHouseContactListDto> list = query.GetPagedList(queryDto.PageIndex, queryDto.PageSize); if (list.Any()) { var sqlList = new List <string>(); foreach (var item in list) { sqlList.Add($"SELECT CONVERT(bigint,{item.Id}) AS ID ,COUNT(0) AS Value,NULL AS Code FROM MlsContactRecordLog WHERE Id<={item.Id} AND UserId={item.UserInfo.UserId} AND OperationType={(int)item.OperationType}"); } var sql = string.Join(" UNION ALL ", sqlList); foreach (var item in this.db.IDValueDto.FromSqlRaw(sql)) { list.Where(c => c.Id == (int)item.ID).First().HowTimes = item.Value; } } var data = new PagedList <ResaleHouseContactListDto>(list.CurrentPageIndex, list.PageSize, list.TotalItemCount); data.AddRange(list); var res = new ContactByResaleHouseDto() { ContactPage = data }; res.HouseInfo = (from housenew in db.ChineseHouseNewQuery join communities in db.ChineseCommunitiesQuery on housenew.CommunityId equals communities.Id where housenew.Id == queryDto.HouseId select new HouseByContactDto { Id = housenew.Id, Areas = housenew.Areas, RentPrice = housenew.RentPrice, TotalPrice = housenew.TotalPrice, ResaleHouseCommodityType = (EnumResaleHouseCommodityType)housenew.HouseSource, CommissionPartnerType = housenew.CommissionPartnerType.GetValueOrDefault(0), CommissionPartner = housenew.CommissionPartner.GetValueOrDefault(0), CommissionPartnerPercent = housenew.CommissionPartnerPercent.GetValueOrDefault(0), BedRoomsCount = housenew.BedRoomsCount.GetValueOrDefault(0), BathRoomsCount = housenew.BathRoomsCount.GetValueOrDefault(0), MainPhotoUrl = housenew.MainPhoto, CommunityName = housenew.CommunityName, AreaName = communities.AreaName, CityName = communities.CityName, IsMls = housenew.ShareToFdb == 2 }).First(); return(res); }
/// <summary> /// Finds a paginated list of APConnections for the given type and search criteria. /// </summary> /// <param name="type">The type (relation name) of the connection.</param> /// <param name="freeTextExpression">Free text search expression over all fields of the given type.</param> /// <param name="query">The search query</param> /// <param name="fields">The specific fields of the conection to be retrieved.</param> /// <param name="pageNumber">The page number.</param> /// <param name="pageSize">The page size.</param> /// <param name="orderBy">The field on which to sort.</param> /// <param name="sortOrder">Sort order - Ascending or Descending.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> /// <returns>A paginated list of APConnections for the given search criteria.</returns> public async static Task<PagedList<APConnection>> FindAllAsync(string type, string freeTextExpression, IQuery query = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null) { query = query ?? Query.None; var request = new FindAllConnectionsRequest() { Type = type, FreeTextExpression = freeTextExpression, Query = query.AsString().Escape(), PageNumber = pageNumber, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var connections = new PagedList<APConnection>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FindAllAsync(type, freeTextExpression, query, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options) }; connections.AddRange(response.Connections); return connections; }
/// <summary> /// Gets a paginated list of APObjects matching the given freetext search expression. /// The provided expression is matched with the entire object instead of a particular field. /// </summary> /// <param name="type">The object type</param> /// <param name="freeTextExpression">Freetext expression.</param> /// <param name="fields">The specific object fields to be retrieved. </param> /// <param name="pageNumber">The page number.</param> /// <param name="pageSize">The page size.</param> /// <param name="orderBy">The object field on which the results should be sorted.</param> /// <param name="sortOrder">The sort order.</param> /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param> /// <returns>Paginated list of APObject objects matching the given search criteria.</returns> public async static Task<PagedList<APObject>> FreeTextSearchAsync(string type, string freeTextExpression, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending, ApiOptions options = null) { var request = new FreeTextSearchObjectsRequest() { Type = type, FreeTextExpression = freeTextExpression, PageNumber = pageNumber, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; if (fields != null) request.Fields.AddRange(fields); ApiOptions.Apply(request, options); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var objects = new PagedList<APObject>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FreeTextSearchAsync(type, freeTextExpression, fields, pageNumber + skip + 1, pageSize, orderBy, sortOrder, options) }; objects.AddRange(response.Objects); return objects; }
public IPagedList <PropertyRent> GetRentListRecords(int page = 0, int results = int.MaxValue, string sortField = "", string sortOrder = "", string tabKey = "即将过期", params PropertySortCondition[] sortConditions) { var query = _propertyRentRepository.Table.AsNoTracking(); Expression <Func <CSCZJ.Core.Domain.Properties.PropertyRent, bool> > expression = p => !p.Deleted; var now = DateTime.Now; var rents = new List <PropertyRent>(); query = query.Where(expression); switch (tabKey) { case "即将过期": query = query.Where(p => System.Data.Entity.DbFunctions.DiffDays(now, p.BackTime) >= 0 && System.Data.Entity.DbFunctions.DiffDays(now, p.BackTime) < 30); break; case "已经过期": query = query.Where(p => System.Data.Entity.DbFunctions.DiffDays(now, p.BackTime) < 0); break; case "全部信息": break; } var defaultSort = new PropertySortCondition("Id", System.ComponentModel.ListSortDirection.Ascending); if (sortField == "" || sortField == null || sortField == "null") { sortField = "BackTime"; defaultSort = new PropertySortCondition(sortField, System.ComponentModel.ListSortDirection.Ascending); } else { sortField = sortField.Substring(0, 1).ToUpper() + sortField.Substring(1); if (sortOrder == "ascend") { defaultSort = new PropertySortCondition(sortField, System.ComponentModel.ListSortDirection.Ascending); } else { defaultSort = new PropertySortCondition(sortField, System.ComponentModel.ListSortDirection.Descending); } } if (sortConditions != null && sortConditions.Length != 0) { query = query.Sort(sortConditions[0]); } else { query = query.Sort(defaultSort); } var reds = new PagedList <CSCZJ.Core.Domain.Properties.PropertyRent>(); reds.TotalCount = query.Count(); reds.TotalPages = query.Count() / results; if (query.Count() % results > 0) { reds.TotalPages++; } reds.PageSize = results; reds.PageIndex = page; reds.AddRange(query.ToList()); return(reds); }
public async static Task<PagedList<Article>> GetConnectedArticlesAsync(string relation, string articleId, string query = null, string label = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20) { var request = new FindConnectedArticlesRequest { Relation = relation, ArticleId = articleId, Label = label, Query = query, PageNumber = pageNumber, PageSize = pageSize }; if (fields != null) request.Fields.AddRange(fields); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); IEnumerable<Article> articles = null; // if label is specified, then get the labelled endpoint if (string.IsNullOrWhiteSpace(label) == false) articles = response.Connections.Select(c => c.Endpoints[label].Content); else articles = response.Connections.Select(c => { if (c.Endpoints.EndpointA.ArticleId == articleId) return c.Endpoints.EndpointB.Content; else return c.Endpoints.EndpointA.Content; }); var list = new PagedList<Article>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await GetConnectedArticlesAsync(relation, articleId, query, label, fields, pageNumber + skip + 1, pageSize) }; list.AddRange(articles); return list; }
public async static Task<PagedList<Connection>> GetConnectionsAsync(string relation, string articleId, string query = null, IEnumerable<string> fields = null, int pageNumber = 1, int pageSize = 20) { IConnectionService connService = ObjectFactory.Build<IConnectionService>(); var request = new FindConnectedArticlesRequest { Relation = relation, ArticleId = articleId, Query = query, PageNumber = pageNumber, PageSize = pageSize }; if (fields != null) request.Fields.AddRange(fields); var response = await connService.FindConnectedArticlesAsync(request); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var list = new PagedList<Connection> { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await GetConnectionsAsync(relation, articleId, query, fields, pageNumber + skip + 1, pageSize) }; list.AddRange(response.Connections); return list; }
public Core.PagedList <Core.Domain.Properties.PropertyPatrol> GetPatrolListRecords(int page = 0, int results = int.MaxValue, string sortField = "", string sortOrder = "", string tabKey = "即将过期", params Core.PropertySortCondition[] sortConditions) { var query = _propertyPatrolRepository.Table.AsNoTracking(); Expression <Func <CSCZJ.Core.Domain.Properties.PropertyPatrol, bool> > expression = p => !p.Deleted; var now = DateTime.Now; var patrols = new List <PropertyPatrol>(); query = query.Where(expression); switch (tabKey) { case "今年巡查": query = query.Where(p => p.PatrolDate.Year == now.Year); break; case "往年巡查": query = query.Where(p => p.PatrolDate.Year < now.Year); break; case "全部": break; } var defaultSort = new PropertySortCondition("Id", System.ComponentModel.ListSortDirection.Ascending); if (sortField == "" || sortField == null || sortField == "null") { sortField = "PatrolDate"; defaultSort = new PropertySortCondition(sortField, System.ComponentModel.ListSortDirection.Ascending); } else { sortField = sortField.Substring(0, 1).ToUpper() + sortField.Substring(1); if (sortOrder == "ascend") { defaultSort = new PropertySortCondition(sortField, System.ComponentModel.ListSortDirection.Ascending); } else { defaultSort = new PropertySortCondition(sortField, System.ComponentModel.ListSortDirection.Descending); } } if (sortConditions != null && sortConditions.Length != 0) { query = query.Sort(sortConditions[0]); } else { query = query.Sort(defaultSort); } var reds = new PagedList <CSCZJ.Core.Domain.Properties.PropertyPatrol>(); reds.TotalCount = query.Count(); reds.TotalPages = query.Count() / results; if (query.Count() % results > 0) { reds.TotalPages++; } reds.PageSize = results; reds.PageIndex = page; reds.AddRange(query.ToList()); return(reds); }
public async Task <PagedList <MessageModel> > GetMessagesAsync(MessageFilter filter, ListOptions listOptions) { var query = Context.Messages.Include(m => m.Author).Include(m => m.Files.Select(f => f.File)).AsQueryable(); var list = new PagedList <MessageModel>(); Expression <Func <Message, bool> > predicate = null; if (list.TotalItemCount == 0) { return(list); } if (listOptions != null) { list.Page = listOptions.Page; list.PageSize = listOptions.PageSize; query = query.OrderByDescending(t => t.CreationDate).Skip(listOptions.Offset).Take(listOptions.PageSize); } if (filter != null) { if (!string.IsNullOrEmpty(filter.SearchString)) { predicate = predicate.AndAlso(m => m.Content.Contains(filter.SearchString)); } if (filter.AttachedFilesCount.HasValue) { predicate = predicate.AndAlso(m => m.Files.Count == filter.AttachedFilesCount); } if (filter.AuthorId.HasValue) { predicate = predicate.AndAlso(m => m.AuthorId == filter.AuthorId); } if (filter.ThemeId.HasValue) { predicate = predicate.AndAlso(m => m.ThemeId == filter.ThemeId); } if (filter.CreateDateAfter.HasValue) { predicate = predicate.AndAlso(m => m.CreationDate >= filter.CreateDateAfter); } if (filter.CreateDateBefore.HasValue) { predicate = predicate.AndAlso(m => m.CreationDate <= filter.CreateDateBefore); } } if (predicate != null) { query = query.Where(predicate); list.TotalItemCount = await Context.Messages.CountAsync(predicate); } else { list.TotalItemCount = await Context.Messages.CountAsync(); } var messages = await query.ToArrayAsync(); list.AddRange(Mapper.Map <IEnumerable <Message>, IEnumerable <MessageModel> >(messages)); return(list); }
/// <summary> /// Gets a paged list of all matching users. /// </summary> /// <param name="query">Filter query to filter out a specific list of users. </param> /// <param name="fields">List of fields to return</param> /// <param name="page">Page number</param> /// <param name="pageSize">Page size</param> /// <returns>A paged list of users.</returns> public async static Task<PagedList<User>> FindAllAsync(string query = null, IEnumerable<string> fields = null, int page = 1, int pageSize = 20, string orderBy = null, SortOrder sortOrder = SortOrder.Descending) { var request = new FindAllUsersRequest() { Query = query, PageNumber = page, PageSize = pageSize, OrderBy = orderBy, SortOrder = sortOrder }; if (fields != null) request.Fields.AddRange(fields); var response = await request.ExecuteAsync(); if (response.Status.IsSuccessful == false) throw response.Status.ToFault(); var users = new PagedList<User>() { PageNumber = response.PagingInfo.PageNumber, PageSize = response.PagingInfo.PageSize, TotalRecords = response.PagingInfo.TotalRecords, GetNextPage = async skip => await FindAllAsync(query, fields, page + skip + 1, pageSize) }; users.AddRange(response.Articles); return users; }