// GET: Settings/Places public ActionResult Index(SearchCountryViewModel searchModel) { PagedEntity <CountryViewModel> result = _placesService.GetCountries(searchModel); searchModel.Items = new PagedList.StaticPagedList <CountryViewModel>(result.Items , searchModel.PageIndex + 1, searchModel.PageSize, result.TotalCount); return(View(searchModel)); }
public async Task <PagedEntity <IReadOnlyCollection <WarLog> > > GetWarLogAsync(string clanTag, int?limit = null, string before = null, string after = null) { if (string.IsNullOrWhiteSpace(clanTag)) { throw new ArgumentNullException(clanTag); } if (limit < 0) { throw new ArgumentOutOfRangeException(nameof(limit)); } clanTag = clanTag[0] == '#' ? clanTag.Replace("#", "%23") : clanTag; var sb = new StringBuilder(); sb.Append($"/v1/clans/{clanTag}/warlog?"); if (limit.HasValue) { sb.Append($"limit={limit.Value}&"); } if (!string.IsNullOrWhiteSpace(before)) { sb.Append($"before={before}&"); } if (!string.IsNullOrWhiteSpace(after)) { sb.Append($"after={after}&"); } var model = await _request.SendAsync <PagedWarlogModel>(sb.ToString()).ConfigureAwait(false); if (model is null) { var empty = ReadOnlyCollection <WarLog> .EmptyCollection(); return(new PagedEntity <IReadOnlyCollection <WarLog> > { Entity = empty }); } var collection = new ReadOnlyCollection <WarLog>(model.WarLogs.Select(x => new WarLog(x)), () => model.WarLogs.First().TeamSize); var paged = new PagedEntity <IReadOnlyCollection <WarLog> > { After = model.Paging.Cursors.After, Before = model.Paging.Cursors.Before, Entity = collection }; return(paged); }
public async Task <PagedEntity <T> > GetAllPagedAsync(int page, int size, int filter, bool order, Expression <Func <T, bool> > predicate) { var pagedEntity = new PagedEntity <T>(); var skipCount = getSkipCount(page, size); var result = _table.Where(predicate); pagedEntity.Count = await result.CountAsync(); pagedEntity.Entities = await result.Skip(skipCount).Take(size).ToListAsync(); return(pagedEntity); }
public PagedEntity <T2> GetPaged <T2>(int pageIndex, int pageSize, string orderBy, ICollection <Tuple <string, string, object> > parameters, string conditionKey = "and", string sqlNoValue = "") { var tableName = SqlMapperExtensions.GetTableName(typeof(T2)); var baseSelectSql = $"select * from {tableName}"; var countsql = $"select count(1) from {tableName} "; var sql = new StringBuilder(); var dynamicParameters = new DynamicParameters(); if (parameters != null) { for (var i = 0; i < parameters.Count; i++) { var parameter = parameters.ElementAt(i); var parameterName = $"{parameter.Item1}"; if (i == 0) { sql.AppendFormat(" where {0} {1} @{2}", parameter.Item1, parameter.Item2, parameterName); } else { sql.AppendFormat(" {0} {1} {2} @{3}", conditionKey, parameter.Item1, parameter.Item2, parameterName); } dynamicParameters.Add(parameterName, parameter.Item3); } } if (!string.IsNullOrEmpty(sqlNoValue)) { sql.Append(parameters != null && parameters.Count > 0 ? sqlNoValue : $" where 1=1 {sqlNoValue}"); } var entities = new PagedEntity <T2> { Items = new List <T2>() }; OpenSlaveConnection(conn => { entities.TotalItems = conn.Query <int>($"{countsql}{sql.ToString()}", dynamicParameters).FirstOrDefault(); if (entities.TotalItems == 0) { return; } sql.AppendFormat(" order by {0} limit @pageIndex,@pageSize", orderBy); dynamicParameters.Add("pageIndex", pageIndex * pageSize); dynamicParameters.Add("pageSize", pageSize); entities.Items = conn.Query <T2>($"{baseSelectSql}{sql.ToString()}", dynamicParameters).ToList(); }); return(entities); }
public virtual PagedEntity <T2> GetPagedEntity <T2>(int pageIndex, int pageSize, string orderBy, ICollection <Tuple <string, string, object> > parameters) { var baseSelectSql = GetBaseSelectSqlForNoStatus(typeof(T2)); var tableName = SqlMapperExtensions.GetTableName(typeof(T2)); var allProperties = SqlMapperExtensions.TypePropertiesCache(typeof(T2)); var computedProperties = SqlMapperExtensions.ComputedPropertiesCache(typeof(T2)); var allPropertiesExceptComputed = allProperties.Except(computedProperties); bool status = false; var hasStatus = allPropertiesExceptComputed.FirstOrDefault(o => o.Name == "Status"); if (hasStatus != null) { status = !SqlMapperExtensions.ExcludeStatus(hasStatus); } var countsql = string.Format("select count(1) from {0} where 1 = 1", tableName); var sql = new StringBuilder(); var dynamicParameters = new DynamicParameters(); if (parameters != null) { for (var i = 0; i < parameters.Count; i++) { var parameter = parameters.ElementAt(i); var parameterName = string.Format("{0}{1}", parameter.Item1, i); sql.AppendFormat(" and {0} {1} @{2}", parameter.Item1, parameter.Item2, parameterName); dynamicParameters.Add(parameterName, parameter.Item3); } } if (status) { sql.Append(" and Status = 1"); } var entities = new PagedEntity <T2>(); entities.Items = new List <T2>(); OpenSlaveConnection(conn => { entities.TotalItems = conn.Query <int>(string.Format("{0}{1}", countsql, sql.ToString()), dynamicParameters).FirstOrDefault(); if (entities.TotalItems == 0) { return; } sql.AppendFormat(" order by {0} limit @pageIndex,@pageSize", orderBy); dynamicParameters.Add("pageIndex", pageIndex * pageSize); dynamicParameters.Add("pageSize", pageSize); entities.Items = conn.Query <T2>(string.Format("{0}{1}", baseSelectSql, sql.ToString()), dynamicParameters).ToList(); }); return(entities); }
public PagedEntity <ViewUserViewModel> SearchUser(SearchUsersViewModel searchUserModel) { if (searchUserModel == null) { throw new ArgumentNullException("searchUserModel"); } PagedEntity <User> result = _securityUnitOfWork.UserRepository.SearchUsers(searchUserModel.UserName, searchUserModel.Email , searchUserModel.FullName , searchUserModel.PageIndex, searchUserModel.PageSize); return(new PagedEntity <ViewUserViewModel>(result.Items.Select(c => GetViewUserViewModel(c)), result.TotalCount)); }
public async Task <PagedEntity <T> > GetAllPagedAsync(int page, int size) { var skipCount = GetSkipCount(page, size); var pagedEntity = new PagedEntity <T>(); var result = _table.AsQueryable(); pagedEntity.Count = await result.CountAsync(); pagedEntity.Entities = await result.Skip(skipCount).Take(size).ToListAsync(); return(pagedEntity); }
public BaseDtoPaged(IMapper mapper, PagedEntity <W> entities, int page, int size) { this.Page = page; this.Size = size; this.Count = entities.Count; var entitiyList = new List <T> (); foreach (var e in entities.Entities) { entitiyList.Add(mapper.Map <W, T>(e)); } this.Entities = entitiyList; }
// GET: Settings/Places public ActionResult Index(SearchCountryViewModel searchModel) { PagedEntity <CountryViewModel> result = _placesService.GetCountries(searchModel); var pagedList = new PagedList.StaticPagedList <CountryViewModel>(result.Items , searchModel.PageIndex + 1, searchModel.PageSize, result.TotalCount); if (pagedList.Count == 0 && pagedList.TotalItemCount > 0) { searchModel.PageIndex = pagedList.HasPreviousPage ? pagedList.PageNumber - 2 : 0; return(RedirectToAction("Index", searchModel)); } searchModel.Items = pagedList; return(View(searchModel)); }
public PagedEntity <T2> GetPagedEntity <T2>(int pageIndex, int pageSize, string orderBy, ICollection <Tuple <string, string, object> > parameters) { var entities = new PagedEntity <T2>(); var collection = MongoDataBase.GetCollection <T2>(DataBase); var queries = new List <IMongoQuery>(); if (parameters != null) { foreach (var parameter in parameters) { queries.Add(Query.EQ(parameter.Item1, BsonValue.Create(parameter.Item3))); } } MongoCursor <T2> cursor; if (queries.Count > 0) { cursor = collection.Find(Query.And(queries)); } else { cursor = collection.FindAll(); } IMongoSortBy sortBy; var value = orderBy.Split(' '); if (value.Length == 2) { if (value[1] == "asc") { sortBy = SortBy.Ascending(value[0]); } else { sortBy = SortBy.Descending(value[0]); } } else { sortBy = SortBy.Descending(orderBy); } //CreateTime entities.Items = cursor.SetSortOrder(sortBy).SetSkip(pageIndex * pageSize).SetLimit(pageSize).ToList(); entities.TotalItems = (int)cursor.Count(); return(entities); }
private FileDtoPaged GetFilesPaged(PagedEntity <File> pagedEntity, FileDtoPagedQuery fileQuery) { var result = new FileDtoPaged(); var entitiesDtoList = new List <FileDto>(); var files = pagedEntity.Entities; result.Size = fileQuery.Size; result.Count = pagedEntity.Count; result.Page = fileQuery.Page; foreach (var file in files) { var fileDto = _mapper.Map <File, FileDto>(file); entitiesDtoList.Add(fileDto); } result.Entities = entitiesDtoList; return(result); }
public async Task <PagedEntity <PostWithAuthor> > GetAllPagedPostsAsyncWithAuthor(int page, int size, int filter, bool order, Expression <Func <Post, bool> > predicate) { var skipCount = GetSkipCount(page, size); var pagedEntity = new PagedEntity <PostWithAuthor>(); var result = _table.Where(predicate); result = _postSortable.Sort(result, filter, order).Skip(skipCount).Take(size); var joinedResult = result.Include(post => post.Comments).Join( _context.Users, post => post.Blog.UserId, user => user.Id, (post, user) => new PostWithAuthor(post, user) ); pagedEntity.Count = await result.CountAsync(); var enitites = await joinedResult.ToListAsync(); pagedEntity.Entities = enitites; return(pagedEntity); }
/// <summary> /// 分页查询 /// </summary> /// <param name="request"></param> /// <returns></returns> public ResultWithCodeEntity <PagedEntity <TourUserListDTO> > PageList(TourUserRequest request) { var result = new PagedEntity <TourUserListDTO>() { Items = new List <TourUserListDTO>() }; try { var pageResult = tourUserRepository.PageList(request); if (pageResult != null) { result.TotalItems = pageResult.TotalItems; result.Items = Mapper.Map <List <TourUserListDTO> >(pageResult.Items); } return(Result.Success <PagedEntity <TourUserListDTO> >(result)); } catch (Exception ex) { return(Result.Error <PagedEntity <TourUserListDTO> >(ResultCode.ExceptionError)); } }
public async Task <PagedEntity <CaseViewModel> > GetCases(SearchCaseViewModel searchViewModel) { if (searchViewModel == null) { throw new ArgumentNullException(nameof(searchViewModel)); } var caseSearch = new CaseSearch { CaseName = searchViewModel.CaseName, CaseStatus = (Sanable.Cases.Domain.Model.CaseStatus)searchViewModel.CaseStatus, CaseType = (Sanable.Cases.Domain.Model.CaseTypes)searchViewModel.CaseType, CityId = searchViewModel.CityId, CountryId = searchViewModel.CountryId, DistrictId = searchViewModel.DistrictId, Phone = searchViewModel.Phone, }; PagedEntity <Case> result = await _caseUnitOfWork.CaseRepository .SearchCases(caseSearch , searchViewModel.PageIndex, searchViewModel.PageSize); return(new PagedEntity <CaseViewModel>(result.Items.Select(c => GetCaseViewModel(c)), result.TotalCount)); }
public PagedEntity <Question> GetAll(int page = 1, int pageSize = 10) { if (pageSize < 1) { pageSize = 10; } if (page < 1) { page = 1; } var totalRecords = repository.Get().Count(); var pagedEntity = new PagedEntity <Question>() { TotalRecords = totalRecords, CurrentPage = page, TotalPages = Convert.ToInt32(Math.Ceiling((double)totalRecords / pageSize)), PageSize = pageSize, PagedData = repository.Get(page: page, pageSize: pageSize).ToList() }; return(pagedEntity); }
public PostDtoPagedWithAuthor(IMapper mapper, PagedEntity <PostWithAuthor> entities, int page, int size) : base(mapper, entities, page, size) { }
public BlogDtoPaged(IMapper mapper, PagedEntity <BlogEntity> entities, int page, int size) : base(mapper, entities, page, size) { }
public PostDtoPaged(IMapper mapper, PagedEntity <Post> entities, int page, int size) : base(mapper, entities, page, size) { }