예제 #1
0
        public JsonResult List(SearchQuestionInput input)
        {
            CheckPermission();

            using (var result = new ResponseResult <List <SearchQutionOutput> >())
            {
                var predicate = PredicateBuilder.True <T_QUESTION>();
                if (!string.IsNullOrEmpty(input.Keywords))
                {
                    predicate = predicate.And(m => m.Title.Contains(input.Keywords));
                }

                if (input.IsOpen.HasValue)
                {
                    predicate = predicate.And(m => m.IsOpen == input.IsOpen);
                }

                if (input.IsDeleted.HasValue)
                {
                    predicate = predicate.And(m => m.IsDeleted == input.IsDeleted);
                }

                long totalCount;
                var  list = _expertQuestionService.GetAll <DateTime>(predicate, null, m => m.CreateTime, input.PageIndex, input.PageSize, out totalCount);
                result.Entity = Mapper.Map <List <SearchQutionOutput> >(list);
                var enumerable = list as T_QUESTION[] ?? list.ToArray();
                if (enumerable.Any())
                {
                    //提取用户编号
                    var userIdList = enumerable.Select(m => m.UserId).Distinct().ToArray();
                    var userList   = _userService.GetAll(m => userIdList.Contains(m.Id));
                    var users      = userList as T_USER[] ?? userList.ToArray();
                    foreach (var question in result.Entity)
                    {
                        var user = users.First(m => m.Id == question.UserId);
                        question.CreateUser = string.IsNullOrEmpty(user.UserName) ? user.LoginUserName : user.UserName;
                    }
                }

                SetJosnResult <List <SearchQutionOutput> >(result, input.PageIndex, input.PageSize,
                                                           totalCount, "获取问题列表成功!");

                return(new JsonResultEx(result));
            }
        }
예제 #2
0
        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));
            }
        }