public virtual async Task <PagedResultDto <TopicCategoryDto> > GetAll(TopicCategoryFilterDto input) { var query = postCategoryRepository.GetAll() .WhereIf(input.Id != null, p => p.Id == input.Id); var totalCount = await query.CountAsync(); query = ApplySorting(query, input); query = ApplyPaging(query, input); var entities = await query.ToListAsync(); return(new PagedResultDto <TopicCategoryDto>( totalCount, entities.Select(p => p.MapTo <TopicCategoryDto>()) .ToList() )); }
protected virtual IQueryable <TopicCategory> ApplyPaging(IQueryable <TopicCategory> query, TopicCategoryFilterDto input) { var pagedInput = input as IPagedResultRequest; if (pagedInput != null) { return(query.PageBy(pagedInput)); } var limitedInput = input as ILimitedResultRequest; if (limitedInput != null) { return(query.Take(limitedInput.MaxResultCount)); } return(query); }
protected virtual IQueryable <TopicCategory> ApplySorting(IQueryable <TopicCategory> query, TopicCategoryFilterDto input) { var sortInput = input as ISortedResultRequest; if (sortInput != null) { if (sortInput.Sorting.IsNotNullOrEmpty()) { return(query.OrderBy(sortInput.Sorting)); } } if (input is ILimitedResultRequest) { return(query.OrderByDescending(e => e.Id)); } return(query); }