public IActionResult ProductAddPopup(string btnId, CustomerTagProductModel.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 customerTagProduct = _customerTagService.GetCustomerTagProduct(model.CustomerTagId, id); if (customerTagProduct == null) { customerTagProduct = new CustomerTagProduct(); customerTagProduct.CustomerTagId = model.CustomerTagId; customerTagProduct.ProductId = id; customerTagProduct.DisplayOrder = 0; _customerTagService.InsertCustomerTagProduct(customerTagProduct); } } } } //a vendor should have access only to his products ViewBag.RefreshPage = true; ViewBag.btnId = btnId; return View(model); }
/// <summary> /// Delete a customer tag product /// </summary> /// <param name="customerTagProduct">Customer tag product</param> public virtual void DeleteCustomerTagProduct(CustomerTagProduct customerTagProduct) { if (customerTagProduct == null) { throw new ArgumentNullException("customerTagProduct"); } _customerTagProductRepository.Delete(customerTagProduct); //clear cache _cacheManager.RemoveByPattern(string.Format(CUSTOMERTAGPRODUCTS_ROLE_KEY, customerTagProduct.CustomerTagId)); _cacheManager.RemoveByPattern(PRODUCTS_CUSTOMER_TAG); //event notification _eventPublisher.EntityDeleted(customerTagProduct); }
/// <summary> /// Inserts a customer tag product /// </summary> /// <param name="customerTagProduct">Customer tag product</param> public virtual async Task InsertCustomerTagProduct(CustomerTagProduct customerTagProduct) { if (customerTagProduct == null) { throw new ArgumentNullException("customerTagProduct"); } await _customerTagProductRepository.InsertAsync(customerTagProduct); //clear cache _cacheManager.RemoveByPattern(string.Format(CUSTOMERTAGPRODUCTS_ROLE_KEY, customerTagProduct.CustomerTagId)); _cacheManager.RemoveByPattern(PRODUCTS_CUSTOMER_TAG); //event notification await _eventPublisher.EntityInserted(customerTagProduct); }
/// <summary> /// Delete a customer tag product /// </summary> /// <param name="customerTagProduct">Customer tag product</param> public virtual async Task DeleteCustomerTagProduct(CustomerTagProduct customerTagProduct) { if (customerTagProduct == null) { throw new ArgumentNullException("customerTagProduct"); } await _customerTagProductRepository.DeleteAsync(customerTagProduct); //clear cache await _cacheManager.RemoveAsync(string.Format(CacheKey.CUSTOMERTAGPRODUCTS_ROLE_KEY, customerTagProduct.CustomerTagId)); await _cacheManager.RemoveByPrefix(CacheKey.PRODUCTS_CUSTOMER_TAG_PATTERN); //event notification await _mediator.EntityDeleted(customerTagProduct); }
public virtual void InsertProductModel(CustomerTagProductModel.AddProductModel model) { foreach (string id in model.SelectedProductIds) { var product = _productService.GetProductById(id); if (product != null) { var customerTagProduct = _customerTagService.GetCustomerTagProduct(model.CustomerTagId, id); if (customerTagProduct == null) { customerTagProduct = new CustomerTagProduct(); customerTagProduct.CustomerTagId = model.CustomerTagId; customerTagProduct.ProductId = id; customerTagProduct.DisplayOrder = 0; _customerTagService.InsertCustomerTagProduct(customerTagProduct); } } } }