コード例 #1
0
        /// <summary>
        /// Prepare paged discount product list model
        /// </summary>
        /// <param name="searchModel">Discount product search model</param>
        /// <param name="discount">Discount</param>
        /// <returns>Discount product list model</returns>
        public virtual DiscountProductListModel PrepareDiscountProductListModel(DiscountProductSearchModel searchModel, Discount discount)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //get products with applied discount
            var discountProducts = _productService.GetProductsWithAppliedDiscount(discountId: discount.Id,
                                                                                  showHidden: false,
                                                                                  pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new DiscountProductListModel().PrepareToGrid(searchModel, discountProducts, () =>
            {
                //fill in model values from the entity
                return(discountProducts.Select(product =>
                {
                    var discountProductModel = product.ToModel <DiscountProductModel>();
                    discountProductModel.ProductId = product.Id;
                    discountProductModel.ProductName = product.Name;

                    return discountProductModel;
                }));
            });

            return(model);
        }
コード例 #2
0
        /// <summary>
        /// Prepare paged discount product list model
        /// </summary>
        /// <param name="searchModel">Discount product search model</param>
        /// <param name="discount">Discount</param>
        /// <returns>Discount product list model</returns>
        public virtual DiscountProductListModel PrepareDiscountProductListModel(DiscountProductSearchModel searchModel, Discount discount)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

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

            //prepare grid model
            var model = new DiscountProductListModel
            {
                //fill in model values from the entity
                Data = discountProducts.Select(product => new DiscountProductModel
                {
                    ProductId   = product.Id,
                    ProductName = product.Name
                }),
                Total = discountProducts.TotalCount
            };

            return(model);
        }