コード例 #1
0
        /// <summary>
        /// Prepare paged category list model to add to the discount
        /// </summary>
        /// <param name="searchModel">Category search model to add to the discount</param>
        /// <returns>Category list model to add to the discount</returns>
        public virtual AddCategoryToDiscountListModel PrepareAddCategoryToDiscountListModel(AddCategoryToDiscountSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get categories
            var categories = _categoryService.GetAllCategories(showHidden: true,
                                                               categoryName: searchModel.SearchCategoryName,
                                                               pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new AddCategoryToDiscountListModel().PrepareToGrid(searchModel, categories, () =>
            {
                return(categories.Select(category =>
                {
                    //fill in model values from the entity
                    var categoryModel = category.ToModel <CategoryModel>();

                    //fill in additional values (not existing in the entity)
                    categoryModel.Breadcrumb = _categoryService.GetFormattedBreadCrumb(category);
                    categoryModel.SeName = _urlRecordService.GetSeName(category, 0, true, false);

                    return categoryModel;
                }));
            });

            return(model);
        }
コード例 #2
0
        /// <summary>
        /// Prepare paged category list model to add to the discount
        /// </summary>
        /// <param name="searchModel">Category search model to add to the discount</param>
        /// <returns>Category list model to add to the discount</returns>
        public virtual AddCategoryToDiscountListModel PrepareAddCategoryToDiscountListModel(AddCategoryToDiscountSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get categories
            var categories = _categoryService.GetAllCategories(showHidden: true,
                                                               categoryName: searchModel.SearchCategoryName,
                                                               pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new AddCategoryToDiscountListModel
            {
                Data = categories.Select(category =>
                {
                    //fill in model values from the entity
                    var categoryModel = category.ToModel();

                    //fill in additional values (not existing in the entity)
                    categoryModel.Breadcrumb = category.GetFormattedBreadCrumb(_categoryService);

                    return(categoryModel);
                }),
                Total = categories.TotalCount
            };

            return(model);
        }