public JsonResult MyList(ExpertMyQuestionListInput input) { using (var result = new ResponseResult <List <ExpertMyQuestionListOutput> >()) { long totalCount; //取得问题列表 var list = _expertQuestionService.GetAll <DateTime?>(m => !m.IsDeleted && m.UserId == input.UserId, null, m => m.LastModifiedTime, input.PageIndex, input.PageSize, out totalCount, "User"); result.Entity = Mapper.Map <List <ExpertMyQuestionListOutput> >(list); //从每个问题条目中提取一个图片编号 var pictureIdDictionary = new Dictionary <long, long>(); var count = list.Select(m => { if (m.PictureIds == null) { return(m); } var tempPictureId = m.PictureIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0]; int pictureId; if (int.TryParse(tempPictureId, out pictureId)) { pictureIdDictionary.Add(m.Id, pictureId); } return(m); }).Count(); 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.PageIndex = input.PageIndex; result.PageSize = input.PageSize; result.TotalNums = totalCount; result.Message = "获取提问列表成功"; return(new JsonResultEx(result)); } }
public JsonResult MyList(ExpertMyQuestionListInput input) { var parameters = GetPostParameters(); var responseResult = PostStandardWithSameControllerAction <List <ExpertMyQuestionListOutput> >(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)); }