Beispiel #1
0
        /// <summary>
        /// Updates the customer role product
        /// </summary>
        /// <param name="customerRoleProduct">Customer role product</param>
        public virtual void UpdateCustomerRoleProduct(CustomerRoleProduct customerRoleProduct)
        {
            if (customerRoleProduct == null)
                throw new ArgumentNullException("customerRoleProduct");

            var builder = Builders<CustomerRoleProduct>.Filter;
            var filter = builder.Eq(x => x.Id, customerRoleProduct.Id);
            var update = Builders<CustomerRoleProduct>.Update
                .Set(x => x.DisplayOrder, customerRoleProduct.DisplayOrder);
            var result = _customerRoleProductRepository.Collection.UpdateOneAsync(filter, update).Result;

            //clear cache
            _cacheManager.RemoveByPattern(string.Format(CUSTOMERROLESPRODUCTS_ROLE_KEY, customerRoleProduct.CustomerRoleId));
            _cacheManager.RemoveByPattern(CUSTOMERROLESPRODUCTS_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityUpdated(customerRoleProduct);
        }
Beispiel #2
0
        /// <summary>
        /// Inserts a customer role product
        /// </summary>
        /// <param name="customerRoleProduct">Customer role product</param>
        public virtual void InsertCustomerRoleProduct(CustomerRoleProduct customerRoleProduct)
        {
            if (customerRoleProduct == null)
                throw new ArgumentNullException("customerRoleProduct");

            _customerRoleProductRepository.Insert(customerRoleProduct);

            //clear cache
            _cacheManager.RemoveByPattern(string.Format(CUSTOMERROLESPRODUCTS_ROLE_KEY, customerRoleProduct.CustomerRoleId));
            _cacheManager.RemoveByPattern(CUSTOMERROLESPRODUCTS_PATTERN_KEY);

            //event notification
            _eventPublisher.EntityInserted(customerRoleProduct);
        }
        public ActionResult ProductAddPopup(string btnId, CustomerRoleProductModel.AddProductModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
                return AccessDeniedView();

            if (model.SelectedProductIds != null)
            {
                foreach (int 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);
        }