public ActionResult ProductAddPopup(string btnId, CustomerRoleProductModel.AddProductModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedView());
            }

            if (model.SelectedProductIds != null)
            {
                foreach (string id in model.SelectedProductIds)
                {
                    var product = _productService.GetProductById(id);
                    if (product != null)
                    {
                        var customerRoleProduct = _customerService.GetCustomerRoleProduct(model.CustomerRoleId, id);
                        if (customerRoleProduct == null)
                        {
                            customerRoleProduct = new CustomerRoleProduct();
                            customerRoleProduct.CustomerRoleId = model.CustomerRoleId;
                            customerRoleProduct.ProductId      = id;
                            customerRoleProduct.DisplayOrder   = 0;
                            _customerService.InsertCustomerRoleProduct(customerRoleProduct);
                        }
                    }
                }
            }

            //a vendor should have access only to his products
            ViewBag.RefreshPage = true;
            ViewBag.btnId       = btnId;
            return(View(model));
        }
        public ActionResult ProductAddPopupList(DataSourceRequest command, CustomerRoleProductModel.AddProductModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedView());
            }

            var searchCategoryIds = new List <string>();

            if (!String.IsNullOrEmpty(model.SearchCategoryId))
            {
                searchCategoryIds.Add(model.SearchCategoryId);
            }

            var products = _productService.SearchProducts(
                categoryIds: searchCategoryIds,
                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 async Task <CustomerRoleProductModel.AddProductModel> PrepareProductModel(string customerRoleId)
        {
            var model = new CustomerRoleProductModel.AddProductModel();

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

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

            //manufacturers
            model.AvailableManufacturers.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            foreach (var m in await _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 await _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Shortcut, Value = s.Id.ToString()
                });
            }

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

            //product types
            model.AvailableProductTypes = ProductType.SimpleProduct.ToSelectList().ToList();
            model.AvailableProductTypes.Insert(0, new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = " "
            });
            return(model);
        }
Example #4
0
        public async Task <IActionResult> ProductAddPopup(CustomerRoleProductModel.AddProductModel model)
        {
            if (model.SelectedProductIds != null)
            {
                await _customerRoleViewModelService.InsertProductModel(model);
            }

            //a vendor should have access only to his products
            ViewBag.RefreshPage = true;
            return(View(model));
        }
        public IActionResult ProductAddPopupList(DataSourceRequest command, CustomerRoleProductModel.AddProductModel model)
        {
            var products  = _customerRoleViewModelService.PrepareProductModel(model, command.Page, command.PageSize);
            var gridModel = new DataSourceResult
            {
                Data  = products.products,
                Total = products.totalCount
            };

            return(Json(gridModel));
        }
 public virtual void InsertProductModel(CustomerRoleProductModel.AddProductModel model)
 {
     foreach (string id in model.SelectedProductIds)
     {
         var product = _productService.GetProductById(id);
         if (product != null)
         {
             var customerRoleProduct = _customerService.GetCustomerRoleProduct(model.CustomerRoleId, id);
             if (customerRoleProduct == null)
             {
                 customerRoleProduct = new CustomerRoleProduct();
                 customerRoleProduct.CustomerRoleId = model.CustomerRoleId;
                 customerRoleProduct.ProductId      = id;
                 customerRoleProduct.DisplayOrder   = 0;
                 _customerService.InsertCustomerRoleProduct(customerRoleProduct);
             }
         }
     }
 }
        public ActionResult ProductAddPopup(string customerRoleId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
            {
                return(AccessDeniedView());
            }

            var model = new CustomerRoleProductModel.AddProductModel();

            model.CustomerRoleId = customerRoleId;
            //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(View(model));
        }
        public virtual async Task <(IList <ProductModel> products, int totalCount)> PrepareProductModel(CustomerRoleProductModel.AddProductModel model, int pageIndex, int pageSize)
        {
            var products = await _productService.PrepareProductList(model.SearchCategoryId, model.SearchManufacturerId, model.SearchStoreId, model.SearchVendorId, model.SearchProductTypeId, model.SearchProductName, pageIndex, pageSize);

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