Пример #1
0
        /// <summary>
        /// Prepare paged customer role product list model
        /// </summary>
        /// <param name="searchModel">Customer role product search model</param>
        /// <returns>Customer role product list model</returns>
        public virtual CustomerRoleProductListModel PrepareCustomerRoleProductListModel(CustomerRoleProductSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null)
            {
                searchModel.SearchVendorId = _workContext.CurrentVendor.Id;
            }

            //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 CustomerRoleProductListModel
            {
                //fill in model values from the entity
                Data  = products.Select(product => product.ToModel <ProductModel>()),
                Total = products.TotalCount
            };

            return(model);
        }
Пример #2
0
        /// <summary>
        /// Prepare paged customer role product list model
        /// </summary>
        /// <param name="searchModel">Customer role product search model</param>
        /// <returns>Customer role product list model</returns>
        public virtual CustomerRoleProductListModel PrepareCustomerRoleProductListModel(CustomerRoleProductSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null)
            {
                searchModel.SearchVendorId = _workContext.CurrentVendor.Id;
            }

            //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 CustomerRoleProductListModel().PrepareToGrid(searchModel, products, () =>
            {
                return(products.Select(product =>
                {
                    var productModel = product.ToModel <ProductModel>();
                    productModel.SeName = _urlRecordService.GetSeName(product, 0, true, false);

                    return productModel;
                }));
            });

            return(model);
        }