/// <summary> /// 获取Article的分页列表信息(营销活动 ) /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <PagedResultDto <ArticleListDto> > GetPagedArticles(GetArticlesInput input) { var query = _articleRepository.GetAll() .Where(a => a.Type == ArticleTypeEnum.营销活动) .WhereIf(!string.IsNullOrEmpty(input.Name), a => a.Title.Contains(input.Name)) .WhereIf(!string.IsNullOrEmpty(input.Author), a => a.Author.Contains(input.Author)) .WhereIf(input.Status.HasValue, a => a.PushStatus == input.Status); //TODO:根据传入的参数添加过滤条件 var articleCount = await query.CountAsync(); var articles = await query .OrderByDescending(a => a.PushTime) .ThenByDescending(a => a.CreationTime) .ThenBy(input.Sorting) .PageBy(input) .ToListAsync(); //var articleListDtos = ObjectMapper.Map<List <ArticleListDto>>(articles); var articleListDtos = articles.MapTo <List <ArticleListDto> >(); return(new PagedResultDto <ArticleListDto>( articleCount, articleListDtos )); }
public async Task <PagedResultDto <ArticleListDto> > GetPaged(GetArticlesInput input) { var query = _entityRepository.GetAll(); // TODO:根据传入的参数添加过滤条件 var count = await query.CountAsync(); var entityList = await query .OrderBy(input.Sorting).AsNoTracking() .PageBy(input) .ToListAsync(); // var entityListDtos = ObjectMapper.Map<List<ArticleListDto>>(entityList); var entityListDtos = entityList.MapTo <List <ArticleListDto> >(); return(new PagedResultDto <ArticleListDto>(count, entityListDtos)); }
/// <summary> /// 获取Excel数据 /// </summary> /// <param name="input"></param> /// <returns></returns> private async Task <List <ArticleListDto> > GeArticleNoPage(GetArticlesInput input) { var query = _articleRepository.GetAll() .Where(a => a.Type == input.Type) .WhereIf(!string.IsNullOrEmpty(input.Name), a => a.Title.Contains(input.Name)) .WhereIf(!string.IsNullOrEmpty(input.Author), a => a.Author.Contains(input.Author)) .WhereIf(input.Status.HasValue, a => a.PushStatus == input.Status); //TODO:根据传入的参数添加过滤条件 var articles = await query .OrderByDescending(a => a.PushTime) .ThenByDescending(a => a.CreationTime) .ThenBy(input.Sorting) .ToListAsync(); var articleListDtos = articles.MapTo <List <ArticleListDto> >(); return(articleListDtos); }
public async Task <APIResultDto> ExportArticlesExcel(GetArticlesInput input) { try { var exportData = await GeArticleNoPage(input); var result = new APIResultDto(); result.Code = 0; result.Data = SaveArticleExcel((input.Type == ArticleTypeEnum.经验分享 ? "经验分享.xlsx" : "营销活动.xlsx"), exportData); return(result); } catch (Exception ex) { Logger.ErrorFormat("ExportArticlesExcel errormsg{0} Exception{1}", ex.Message, ex); return(new APIResultDto() { Code = 901, Msg = "网络忙...请待会儿再试!" }); } }