public ActionResult AssociateProductToCustomerRolePopupList(DataSourceRequest command,
                                                                    CustomerRoleModel.AssociateProductToCustomerRoleModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

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

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

            gridModel.Data  = products.Select(x => x.ToModel());
            gridModel.Total = products.TotalCount;

            return(Json(gridModel));
        }
        public virtual IActionResult AssociateProductToCustomerRolePopup(CustomerRoleModel.AssociateProductToCustomerRoleModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var associatedProduct = _productService.GetProductById(model.AssociatedToProductId);

            if (associatedProduct == null)
            {
                return(Content("Cannot load a product"));
            }

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && associatedProduct.VendorId != _workContext.CurrentVendor.Id)
            {
                return(Content("This is not your product"));
            }

            //a vendor should have access only to his products
            model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
            ViewBag.RefreshPage      = true;
            ViewBag.productId        = associatedProduct.Id;
            ViewBag.productName      = associatedProduct.Name;
            return(View(model));
        }
        public virtual CustomerRoleModel.AssociateProductToCustomerRoleModel PrepareAssociateProductToCustomerRoleModel()
        {
            var model = new CustomerRoleModel.AssociateProductToCustomerRoleModel();

            //a vendor should have access only to his products
            model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            //categories
            model.AvailableCategories.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            var categories = _categoryService.GetAllCategories(showHidden: true);

            foreach (var c in categories)
            {
                model.AvailableCategories.Add(new SelectListItem {
                    Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString()
                });
            }

            //manufacturers
            model.AvailableManufacturers.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            foreach (var m in _manufacturerService.GetAllManufacturers(showHidden: true))
            {
                model.AvailableManufacturers.Add(new SelectListItem {
                    Text = m.Name, Value = m.Id.ToString()
                });
            }

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            //vendors
            model.AvailableVendors.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            foreach (var v in _vendorService.GetAllVendors(showHidden: true))
            {
                model.AvailableVendors.Add(new SelectListItem {
                    Text = v.Name, Value = v.Id.ToString()
                });
            }

            //product types
            model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList();
            model.AvailableProductTypes.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            return(model);
        }
        public IActionResult AssociateProductToCustomerRolePopupList(DataSourceRequest command,
                                                                     CustomerRoleModel.AssociateProductToCustomerRoleModel model, [FromServices] IWorkContext workContext)
        {
            //a vendor should have access only to his products
            if (workContext.CurrentVendor != null)
            {
                model.SearchVendorId = workContext.CurrentVendor.Id;
            }
            var products  = _customerRoleViewModelService.PrepareProductModel(model, command.Page, command.PageSize);
            var gridModel = new DataSourceResult();

            gridModel.Data  = products.products.ToList();
            gridModel.Total = products.totalCount;

            return(Json(gridModel));
        }
        public ActionResult AssociateProductToCustomerRolePopup()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var model = new CustomerRoleModel.AssociateProductToCustomerRoleModel();

            //a vendor should have access only to his products
            model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            //categories
            model.AvailableCategories.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var categories = _categoryService.GetAllCategories(showHidden: true);

            foreach (var c in categories)
            {
                model.AvailableCategories.Add(new SelectListItem()
                {
                    Text = c.GetFormattedBreadCrumb(categories), Value = c.Id.ToString()
                });
            }

            //manufacturers
            model.AvailableManufacturers.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var m in _manufacturerService.GetAllManufacturers(showHidden: true))
            {
                model.AvailableManufacturers.Add(new SelectListItem()
                {
                    Text = m.Name, Value = m.Id.ToString()
                });
            }

            //stores
            model.AvailableStores.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem()
                {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            //vendors
            model.AvailableVendors.Add(new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var v in _vendorService.GetAllVendors(0, int.MaxValue, true))
            {
                model.AvailableVendors.Add(new SelectListItem()
                {
                    Text = v.Name, Value = v.Id.ToString()
                });
            }

            //product types
            model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList();
            model.AvailableProductTypes.Insert(0, new SelectListItem()
            {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            return(View(model));
        }
Esempio n. 6
0
        public virtual ActionResult AssociateProductToCustomerRolePopup()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageCustomers))
            {
                return(AccessDeniedView());
            }

            var model = new CustomerRoleModel.AssociateProductToCustomerRoleModel();

            //a vendor should have access only to his products
            model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;

            //categories
            model.AvailableCategories.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var categories = SelectListHelper.GetCategoryList(_categoryService, _cacheManager, true);

            foreach (var c in categories)
            {
                model.AvailableCategories.Add(c);
            }

            //destinations
            model.AvailableDestinations.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var destinations = SelectListHelper.GetDestinationList(_destinationService, _cacheManager, true);

            foreach (var m in destinations)
            {
                model.AvailableDestinations.Add(m);
            }

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            //vendors
            model.AvailableVendors.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var vendors = SelectListHelper.GetVendorList(_vendorService, _cacheManager, true);

            foreach (var v in vendors)
            {
                model.AvailableVendors.Add(v);
            }

            //product types
            model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList(false).ToList();
            model.AvailableProductTypes.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });

            return(View(model));
        }
        public IActionResult AssociateProductToCustomerRolePopup(string btnId, string productIdInput,
                                                                 string productNameInput, CustomerRoleModel.AssociateProductToCustomerRoleModel model, [FromServices] IProductService productService, [FromServices] IWorkContext workContext)
        {
            var associatedProduct = productService.GetProductById(model.AssociatedToProductId);

            if (associatedProduct == null)
            {
                return(Content("Cannot load a product"));
            }

            //a vendor should have access only to his products
            if (workContext.CurrentVendor != null && associatedProduct.VendorId != workContext.CurrentVendor.Id)
            {
                return(Content("This is not your product"));
            }

            //a vendor should have access only to his products
            model.IsLoggedInAsVendor = workContext.CurrentVendor != null;
            ViewBag.RefreshPage      = true;
            ViewBag.productIdInput   = productIdInput;
            ViewBag.productNameInput = productNameInput;
            ViewBag.btnId            = btnId;
            ViewBag.productId        = associatedProduct.Id;
            ViewBag.productName      = associatedProduct.Name;
            return(View(model));
        }
        public virtual (IList <ProductModel> products, int totalCount) PrepareProductModel(CustomerRoleModel.AssociateProductToCustomerRoleModel model, int pageIndex, int pageSize)
        {
            var products = _productService.PrepareProductList(model.SearchCategoryId, model.SearchManufacturerId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId, model.SearchProductName, pageIndex, pageSize);

            return(products.Select(x => x.ToModel()).ToList(), products.TotalCount);
        }