/// <summary> /// Prepare paged category product list model /// </summary> /// <param name="searchModel">Category product search model</param> /// <param name="category">Category</param> /// <returns>Category product list model</returns> public virtual CategoryQuestionListModel PrepareCategoryQuestionListModel(CategoryQuestionSearchModel searchModel, Category category) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (category == null) { throw new ArgumentNullException(nameof(category)); } //get question categories var questionCategories = _categoryService.GetQuestionCategoriesByCategoryId(category.Id, showHidden: true, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize); //prepare grid model var model = new CategoryQuestionListModel().PrepareToGrid(searchModel, questionCategories, () => { return(questionCategories.Select(questionCategory => { //fill in model values from the entity var categoryQuestionModel = questionCategory.ToModel <CategoryQuestionModel>(); //fill in additional values (not existing in the entity) categoryQuestionModel.QuestionName = _questionService.GetQuestionById(questionCategory.QuestionId)?.Name; return categoryQuestionModel; })); }); return(model); }
public virtual IActionResult QuestionList(CategoryQuestionSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermission.ManageQuestions)) { return(AccessDeniedDataTablesJson()); } //try to get a category with the specified id var category = _categoryService.GetCategoryById(searchModel.CategoryId) ?? throw new ArgumentException("No category found with the specified id"); //prepare model var model = _categoryModelFactory.PrepareCategoryQuestionListModel(searchModel, category); return(Json(model)); }
/// <summary> /// Prepare category product search model /// </summary> /// <param name="searchModel">Category product search model</param> /// <param name="category">Category</param> /// <returns>Category product search model</returns> protected virtual CategoryQuestionSearchModel PrepareCategoryQuestionSearchModel(CategoryQuestionSearchModel searchModel, Category category) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } if (category == null) { throw new ArgumentNullException(nameof(category)); } searchModel.CategoryId = category.Id; //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }