/// <summary>
        /// Prepare paged discount category list model
        /// </summary>
        /// <param name="searchModel">Discount category search model</param>
        /// <param name="discount">Discount</param>
        /// <returns>Discount category list model</returns>
        public virtual DiscountCategoryListModel PrepareDiscountCategoryListModel(DiscountCategorySearchModel searchModel, Discount discount)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (discount == null)
            {
                throw new ArgumentNullException(nameof(discount));
            }

            //get categories with applied discount
            var discountCategories = _categoryService.GetCategoriesByAppliedDiscount(discountId: discount.Id,
                                                                                     showHidden: false,
                                                                                     pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new DiscountCategoryListModel().PrepareToGrid(searchModel, discountCategories, () =>
            {
                //fill in model values from the entity
                return(discountCategories.Select(category =>
                {
                    var discountCategoryModel = category.ToModel <DiscountCategoryModel>();

                    discountCategoryModel.CategoryName = _categoryService.GetFormattedBreadCrumb(category);
                    discountCategoryModel.CategoryId = category.Id;

                    return discountCategoryModel;
                }));
            });

            return(model);
        }
Exemple #2
0
        /// <summary>
        /// Prepare paged discount category list model
        /// </summary>
        /// <param name="searchModel">Discount category search model</param>
        /// <param name="discount">Discount</param>
        /// <returns>Discount category list model</returns>
        public virtual DiscountCategoryListModel PrepareDiscountCategoryListModel(DiscountCategorySearchModel searchModel, Discount discount)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (discount == null)
            {
                throw new ArgumentNullException(nameof(discount));
            }

            //get categories with applied discount
            var discountCategories = _discountService.GetCategoriesWithAppliedDiscount(discountId: discount.Id,
                                                                                       showHidden: false,
                                                                                       pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new DiscountCategoryListModel
            {
                //fill in model values from the entity
                Data = discountCategories.Select(category => new DiscountCategoryModel
                {
                    CategoryId   = category.Id,
                    CategoryName = _categoryService.GetFormattedBreadCrumb(category)
                }),
                Total = discountCategories.TotalCount
            };

            return(model);
        }