public JsonResult List(ExpertQuestionSearchInput searchInput) { var parameters = GetPostParameters(); var responseResult = PostStandardWithSameControllerAction <List <ExpertQuestionListOutput> >(this, parameters); if (responseResult.IsSuccess && responseResult.Entity.Count > 0) { foreach (var item in responseResult.Entity) { if (!string.IsNullOrEmpty(item.PictureUrl)) { item.PictureUrl = uploadFileBasePath + item.PictureUrl; } } } return(new JsonResultEx(responseResult)); }
public JsonResult List(ExpertQuestionSearchInput searchInput) { using (var result = new ResponseResult <List <ExpertQuestionListOutput> >()) { long totalCount; var isOpen = searchInput.IsOpen > 0; Expression <Func <T_QUESTION, bool> > predicate; Expression <Func <T_QUESTION, bool> > carouselPredicate; if (searchInput.IsOpen == 0) { carouselPredicate = m => !m.IsDeleted && !m.IsOpen && m.IsPutOnCarousel; } else { carouselPredicate = m => !m.IsDeleted && m.IsOpen && m.IsPutOnCarousel; } var carouselList = _expertQuestionService.GetAll(carouselPredicate, null, m => m.LastModifiedTime, 1, 3, out totalCount, "User"); var carouselQuestionIdList = carouselList.Select(m => m.Id).ToArray(); if (!string.IsNullOrEmpty(searchInput.Keywords)) { predicate = m => !m.IsDeleted && !carouselQuestionIdList.Contains(m.Id) && m.Title.Contains(searchInput.Keywords) && m.IsOpen == isOpen; } else { predicate = m => !m.IsDeleted && !carouselQuestionIdList.Contains(m.Id) && m.IsOpen == isOpen; } var list = _expertQuestionService.GetAll(predicate, null, m => m.LastModifiedTime, searchInput.PageIndex, searchInput.PageSize, out totalCount, "User"); var enumerable = list as T_QUESTION[] ?? list.ToArray(); if (enumerable.Any()) { result.Entity = Mapper.Map <List <ExpertQuestionListOutput> >(list); //从每个问题条目中提取一个图片编号 var pictureIdDictionary = new Dictionary <long, long>(); GetOnePictureIdFromPerQuestion(enumerable, pictureIdDictionary); var picIdArray = pictureIdDictionary.Values.ToArray(); //根据图片编号列表获取图片信息 var fileInfoList = _fileInfoRepository.GetAll(m => picIdArray.Contains(m.Id)); //图片路径赋值 foreach (var item in result.Entity) { if (!pictureIdDictionary.ContainsKey(item.QuestionId)) { continue; } var fileInfo = fileInfoList.FirstOrDefault(m => m.Id == pictureIdDictionary[item.QuestionId]); if (fileInfo != null) { item.PictureUrl = fileInfo.Path; } } } result.TotalNums = totalCount; return(new JsonResultEx(result)); } }