Example #1
0
        /// <summary>
        /// Prepare paged product list model to add to the discount
        /// </summary>
        /// <param name="searchModel">Product search model to add to the discount</param>
        /// <returns>Product list model to add to the discount</returns>
        public virtual AddProductToDiscountListModel PrepareAddProductToDiscountListModel(AddProductToDiscountSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get products
            var products = _productService.SearchProducts(showHidden: true,
                                                          categoryIds: new List <int> {
                searchModel.SearchCategoryId
            },
                                                          manufacturerId: searchModel.SearchManufacturerId,
                                                          storeId: searchModel.SearchStoreId,
                                                          vendorId: searchModel.SearchVendorId,
                                                          productType: searchModel.SearchProductTypeId > 0 ? (ProductType?)searchModel.SearchProductTypeId : null,
                                                          keywords: searchModel.SearchProductName,
                                                          pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare grid model
            var model = new AddProductToDiscountListModel
            {
                //fill in model values from the entity
                Data  = products.Select(product => product.ToModel <ProductModel>()),
                Total = products.TotalCount
            };

            return(model);
        }
        /// <summary>
        /// Prepare product search model to add to the discount
        /// </summary>
        /// <param name="searchModel">Product search model to add to the discount</param>
        /// <returns>Product search model to add to the discount</returns>
        public virtual AddProductToDiscountSearchModel PrepareAddProductToDiscountSearchModel(AddProductToDiscountSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            //prepare available manufacturers
            _baseAdminModelFactory.PrepareManufacturers(searchModel.AvailableManufacturers);

            //prepare available stores
            _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores);

            //prepare available vendors
            _baseAdminModelFactory.PrepareVendors(searchModel.AvailableVendors);

            //prepare available product types
            _baseAdminModelFactory.PrepareProductTypes(searchModel.AvailableProductTypes);

            //prepare page parameters
            searchModel.SetPopupGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare paged product list model to add to the discount
        /// </summary>
        /// <param name="searchModel">Product search model to add to the discount</param>
        /// <returns>
        /// A task that represents the asynchronous operation
        /// The task result contains the product list model to add to the discount
        /// </returns>
        public virtual async Task <AddProductToDiscountListModel> PrepareAddProductToDiscountListModelAsync(AddProductToDiscountSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get products
            var products = await _productService.SearchProductsAsync(showHidden : true,
                                                                     categoryIds : new List <int> {
                searchModel.SearchCategoryId
            },
                                                                     manufacturerIds : new List <int> {
                searchModel.SearchManufacturerId
            },
                                                                     storeId : searchModel.SearchStoreId,
                                                                     vendorId : searchModel.SearchVendorId,
                                                                     productType : searchModel.SearchProductTypeId > 0?(ProductType?)searchModel.SearchProductTypeId : null,
                                                                     keywords : searchModel.SearchProductName,
                                                                     pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize);

            //prepare grid model
            var model = await new AddProductToDiscountListModel().PrepareToGridAsync(searchModel, products, () =>
            {
                return(products.SelectAwait(async product =>
                {
                    var productModel = product.ToModel <ProductModel>();
                    productModel.SeName = await _urlRecordService.GetSeNameAsync(product, 0, true, false);

                    return productModel;
                }));
            });

            return(model);
        }