protected virtual void GetPage <T>(PageListDto <T> vm, IQueryable <T> query, int index, int size) { vm.Index = index < 1 ? 1 : index; vm.Size = size < 1 ? 10 : size; if (vm.Index > 1) { query = query.Skip((vm.Index - 1) * vm.Size); } vm.List = query.Take(vm.Size).ToList(); }
public virtual PageListDto <FileInfoDto> GetPageList(FileInfoPageParamDto vm) { PageListDto <FileInfoDto> result = null; if (vm != null && this.Client.IsLogin) { result = this.Client.Request <PageListDto <FileInfoDto>, FileInfoPageParamDto>(MsgCmd.GetFileInfoPageList, vm); } return(result); }
public virtual PageListDto <UserInfoDto> GetPageList(UserInfoPageParamDto vm) { PageListDto <UserInfoDto> page = null; if (this.Client.IsLogin) { page = this.Client.Request <PageListDto <UserInfoDto>, UserInfoPageParamDto>(MsgCmd.GetUserPageList, vm); } return(page); }
public virtual PageListDto <UserInfoDto> GetPageList(UserInfoPageParamDto vm) { PageListDto <UserInfoDto> result = null; if (vm != null && vm.Index > 0 && vm.Size > 0) { var repository = this.GetRepository <IUserRepository>(); result = repository.GetPageList(vm); } return(result); }
public ActionResult GetPageList(FileInfoPageParamDto vm) { if (vm != null && vm.Index > 0 && vm.Size > 0) { var fileInfoService = this.GetService <IFileInfoService>(); PageListDto <FileInfoDto> data = fileInfoService.GetPageList(vm); return(Success(data)); } return(Error()); }
private void BindListView(PageListDto <UserInfoDto> page) { this.ucPageFooter.SetPageIndex(page.Index, page.TotalCount); this.listView.BeginUpdate(); this.listView.Items.Clear(); if (page.List != null) { foreach (var m in page.List) { var arr = new string[] { m.Name, m.Account, m.RoleName, m.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss") }; ListViewItem item = new ListViewItem(arr); item.Tag = m; item.Name = "id_" + m.Id.ToString(); this.listView.Items.Add(item); } } this.listView.EndUpdate(); }
public virtual PageListDto <UserInfoDto> GetPageList(UserInfoPageParamDto vm) { PageListDto <UserInfoDto> pageList = new PageListDto <UserInfoDto>(); using (var db = this.CreateDbContext()) { var query = from q in db.User join a in db.Role on q.RoleId equals a.Id into b from c in b.DefaultIfEmpty() where q.IsDelete == false select new UserInfoDto { Id = q.Id, Name = q.Name, Account = q.Account, RoleId = q.RoleId, UpdateTime = q.UpdateTime, IsSystem = q.IsSystem, RoleName = c.Name }; if (!string.IsNullOrEmpty(vm.Keyword)) { query = query.Where(q => q.Account.Contains(vm.Keyword.ToLower()) || q.Name.Contains(vm.Keyword) || q.RoleName.Contains(vm.Keyword)); } pageList.TotalCount = query.Count(); switch (vm.Orderby) { case "Name": query = vm.IsDesc ? query.OrderByDescending(q => q.Name) : query.OrderBy(q => q.Name); break; case "Account": query = vm.IsDesc ? query.OrderByDescending(q => q.Account) : query.OrderBy(q => q.Account); break; case "RoleName": query = vm.IsDesc ? query.OrderByDescending(q => q.RoleName) : query.OrderBy(q => q.RoleName); break; case "UpdateTime": query = vm.IsDesc ? query.OrderByDescending(q => q.UpdateTime) : query.OrderBy(q => q.UpdateTime); break; case "Id": default: query = vm.IsDesc ? query.OrderByDescending(q => q.Id) : query.OrderBy(q => q.Id); break; } this.GetPage(pageList, query, vm.Index, vm.Size); } return(pageList); }
public async Task <IActionResult> OData(ODataQueryOptions <DeveloperDto> oDataQuery) { var edmModel = EdmModelConfig.GetEdmModel(); var edmEntitySet = edmModel.FindDeclaredEntitySet(nameof(Developer)); var context = new ODataQueryContext(edmModel, typeof(Developer), oDataQuery.Context.Path); var edmType = context.ElementType; var parameters = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(oDataQuery.RawValues.Filter)) { parameters.Add("$filter", oDataQuery.RawValues.Filter); } if (!string.IsNullOrWhiteSpace(oDataQuery.RawValues.Expand)) { parameters.Add("$expand", oDataQuery.RawValues.Expand); } if (!string.IsNullOrWhiteSpace(oDataQuery.RawValues.OrderBy)) { parameters.Add("$orderby", oDataQuery.RawValues.OrderBy); } var parser = new ODataQueryOptionParser(edmModel, edmType, edmEntitySet, parameters); var queryable = (IQueryable <Developer>)_databaseContext.Developer; if (!string.IsNullOrWhiteSpace(oDataQuery.RawValues.Filter)) { var filter = new FilterQueryOption(oDataQuery.RawValues.Filter, context, parser); queryable = (IQueryable <Developer>)filter.ApplyTo(queryable, new ODataQuerySettings()); } if (!string.IsNullOrWhiteSpace(oDataQuery.RawValues.OrderBy)) { var orderBy = new OrderByQueryOption(oDataQuery.RawValues.OrderBy, context, parser); queryable = orderBy.ApplyTo(queryable, new ODataQuerySettings()); } IQueryable <object> expandableQueryable = null; if (!string.IsNullOrWhiteSpace(oDataQuery.RawValues.Expand)) { var expand = new SelectExpandQueryOption(null, oDataQuery.RawValues.Expand, context, parser); expandableQueryable = (IQueryable <object>)expand.ApplyTo(queryable, new ODataQuerySettings()); } int pageIndex = 1; var hasPageIndex = oDataQuery.Request.Query.TryGetValue("$pageindex", out StringValues pageIndexRaw); if (hasPageIndex) { var isTrue = int.TryParse(pageIndexRaw, out int _pageIndexRaw); pageIndex = (isTrue && _pageIndexRaw > 0) ? _pageIndexRaw : pageIndex; } int pageSize = 10; var hasPageSize = oDataQuery.Request.Query.TryGetValue("$pagesize", out StringValues pageSizeRaw); if (hasPageSize) { var isTrue = int.TryParse(pageSizeRaw, out int _pageSizeRaw); pageSize = (isTrue && _pageSizeRaw > 0) ? _pageSizeRaw : pageSize; } IQueryable <object> queryToExecute = expandableQueryable ?? queryable; var records = await queryToExecute.Skip((pageIndex - 1) *pageSize).Take(pageSize).ToListAsync(); var count = await queryToExecute.CountAsync(); var pageList = new PageList <Developer>(MapDomain(records).ToList(), count, pageIndex, pageSize); var response = PageListDto <DeveloperDto> .Map(pageList, DeveloperDto.MapDomainToDto); return(Ok(response)); }
public virtual PageListDto <FileInfoDto> GetPageList(FileInfoPageParamDto vm) { PageListDto <FileInfoDto> page = new PageListDto <FileInfoDto>(); using (var db = this.CreateDbContext()) { var query = from q in db.FileInfo where q.IsDelete == false && q.ParentId == vm.ParentId select new FileInfoDto { Id = q.Id, ParentId = q.ParentId, Type = q.Type, Directory = q.Directory, Name = q.Name, Length = q.Length, CreationTime = q.CreationTime, LastWriteTime = q.LastWriteTime, Key = q.Key, UpdateTime = q.UpdateTime, IsDelete = q.IsDelete, }; #region where if (vm.Type != FileInfoType.None) { query = query.Where(q => q.Type == vm.Type); } if (vm.BeginCreateTime.HasValue) { query = query.Where(q => q.CreationTime >= vm.BeginCreateTime.Value); } if (vm.EndCreateTime.HasValue) { query = query.Where(q => q.CreationTime < vm.EndCreateTime.Value.AddSeconds(1)); } if (vm.BeginLastWriteTime.HasValue) { query = query.Where(q => q.LastWriteTime >= vm.BeginLastWriteTime.Value); } if (vm.EndLastWriteTime.HasValue) { query = query.Where(q => q.LastWriteTime < vm.EndLastWriteTime.Value.AddSeconds(1)); } if (!string.IsNullOrEmpty(vm.Keyword)) { query = query.Where(q => q.Name.Contains(vm.Keyword.ToLower())); } #endregion page.TotalCount = query.Count(); #region Orderby switch (vm.Orderby) { case "Type": query = vm.IsDesc ? query.OrderByDescending(q => q.Type) : query.OrderBy(q => q.Type); break; case "Name": query = vm.IsDesc ? query.OrderByDescending(q => q.Name) : query.OrderBy(q => q.Name); break; case "Length": query = vm.IsDesc ? query.OrderByDescending(q => q.Length) : query.OrderBy(q => q.Length); break; case "CreationTime": query = vm.IsDesc ? query.OrderByDescending(q => q.CreationTime) : query.OrderBy(q => q.CreationTime); break; case "LastWriteTime": query = vm.IsDesc ? query.OrderByDescending(q => q.LastWriteTime) : query.OrderBy(q => q.LastWriteTime); break; default: query = from q in query orderby q.Type, q.Name select q; break; } #endregion this.GetPage(page, query, vm.Index, vm.Size); } return(page); }
public virtual PageListDto <OptionLogDto> GetPageList(OptionLogPageParamDto vm) { PageListDto <OptionLogDto> pageList = new PageListDto <OptionLogDto>(); using (var db = this.CreateDbContext()) { var query = from q in db.OptionLog select new OptionLogDto { Id = q.Id, Type = q.Type, UserId = q.UserId, UserAccount = q.UserAccount, UserName = q.UserName, Address = q.Address, CreateTime = q.CreateTime, Msg = q.Msg }; if (vm.Type != (int)MsgCmd.None) { query = query.Where(q => q.Type == vm.Type); } if (vm.BeginTime.HasValue) { query = query.Where(q => q.CreateTime >= vm.BeginTime.Value); } if (vm.EndTime.HasValue) { query = query.Where(q => q.CreateTime <= vm.EndTime.Value); } if (!string.IsNullOrEmpty(vm.Keyword)) { query = query.Where(q => q.UserAccount.Contains(vm.Keyword) || q.UserName.Contains(vm.Keyword) || q.Address.Contains(vm.Keyword) || q.Msg.Contains(vm.Keyword)); } pageList.TotalCount = query.Count(); switch (vm.Orderby) { case "Type": query = vm.IsDesc ? query.OrderByDescending(q => q.Type) : query.OrderBy(q => q.Type); break; case "UserAccount": query = vm.IsDesc ? query.OrderByDescending(q => q.UserAccount) : query.OrderBy(q => q.UserAccount); break; case "UserName": query = vm.IsDesc ? query.OrderByDescending(q => q.UserName) : query.OrderBy(q => q.UserName); break; case "CreateTime": query = vm.IsDesc ? query.OrderByDescending(q => q.CreateTime) : query.OrderBy(q => q.CreateTime); break; case "Address": query = vm.IsDesc ? query.OrderByDescending(q => q.Address) : query.OrderBy(q => q.Address); break; default: query = query.OrderByDescending(q => q.Id); break; } this.GetPage(pageList, query, vm.Index, vm.Size); } return(pageList); }