/// <summary>
        /// Prepare product search model
        /// </summary>
        /// <param name="searchModel">Product search model</param>
        /// <returns>Product search model</returns>
        public virtual QuestionSearchModel PrepareQuestionSearchModel(QuestionSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available categories
            _baseAdminModelFactory.PrepareCategories(searchModel.AvailableCategories);

            //prepare available product types
            _baseAdminModelFactory.PrepareQuestionTypes(searchModel.AvailableQuestionTypes);

            //prepare "published" filter (0 - all; 1 - published only; 2 - unpublished only)
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "0",
                Text  = "All"
            });
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "1",
                Text  = "Published only"
            });
            searchModel.AvailablePublishedOptions.Add(new SelectListItem
            {
                Value = "2",
                Text  = "Unpublished only"
            });

            //prepare grid
            searchModel.SetGridPageSize();

            return(searchModel);
        }
        public virtual IActionResult QuestionList(QuestionSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermission.ManageQuestions))
            {
                return(AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = _questionModelFactory.PrepareQuestionListModel(searchModel);

            return(Json(model));
        }
Exemple #3
0
        public ActionResult QuestionList(QuestionSearchModel model)
        {
            //1.初始化默认查询模型
            DateTime today = DateTime.Today;

            if (model.StartTime == null)
            {
                model.StartTime = today.AddDays(-today.Day + 1);
            }
            if (model.EndTime == null)
            {
                model.EndTime = today;
            }
            model.StatusList = GetStatusList();

            int CurrentPlaceId = GetSessionModel().PropertyPlaceId ?? 0;

            //根据提报时间查询
            DateTime endTime = model.EndTime.Value.AddDays(1);

            Expression <Func <T_Question, bool> > where = u => u.UploadTime >= model.StartTime.Value && u.UploadTime < endTime && u.PropertyPlaceId == CurrentPlaceId;

            //根据状态名称查询
            if (model.Status != null)
            {
                where = PredicateBuilder.And(where, u => u.Status == model.Status);
            }

            //根据问题名称模糊查询
            if (!string.IsNullOrEmpty(model.Title))
            {
                where = PredicateBuilder.And(where, u => u.Title.Contains(model.Title));
            }

            //根据查询条件调用BLL层 获取分页数据
            IQuestionBLL questionBll = BLLFactory <IQuestionBLL> .GetBLL("QuestionBLL");

            var sortName = this.SettingSorting("Id", false);

            model.DataList = questionBll.GetPageList(where, sortName.SortName, sortName.IsAsc, model.PageIndex) as PagedList <T_Question>;
            return(View(model));
        }
        /// <summary>
        /// Prepare paged product list model
        /// </summary>
        /// <param name="searchModel">Product search model</param>
        /// <returns>Product list model</returns>
        public virtual QuestionListModel PrepareQuestionListModel(QuestionSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter comments
            var overridePublished = searchModel.SearchPublishedId == 0 ? null : (bool?)(searchModel.SearchPublishedId == 1);
            var categoryIds       = new List <int> {
                searchModel.SearchCategoryId
            };

            if (searchModel.SearchIncludeSubCategories && searchModel.SearchCategoryId > 0)
            {
                var childCategoryIds = _categoryService.GetChildCategoryIds(parentCategoryId: searchModel.SearchCategoryId, showHidden: true);
                categoryIds.AddRange(childCategoryIds);
            }

            //get products
            var questions = _questionService.GetAllQuestions(searchModel.SearchQuestionName,
                                                             categoryIds: categoryIds,
                                                             questionType: searchModel.SearchQuestionTypeId > 0 ? (QuestionType?)searchModel.SearchQuestionTypeId : null,
                                                             pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize,
                                                             overridePublished: overridePublished);

            //prepare list model
            var model = new QuestionListModel().PrepareToGrid(searchModel, questions, () =>
            {
                return(questions.Select(product =>
                {
                    //fill in model values from the entity
                    var questionModel = product.ToModel <QuestionModel>();
                    questionModel.QuestionTypeName = product.QuestionType.ToString();
                    return questionModel;
                }));
            });

            return(model);
        }