Пример #1
0
        /// <summary>
        /// Inserts a customer group product
        /// </summary>
        /// <param name="customerGroupProduct">Customer group product</param>
        public virtual async Task InsertCustomerGroupProduct(CustomerGroupProduct customerGroupProduct)
        {
            if (customerGroupProduct == null)
            {
                throw new ArgumentNullException(nameof(customerGroupProduct));
            }

            await _customerGroupProductRepository.InsertAsync(customerGroupProduct);

            //clear cache
            await _cacheBase.RemoveAsync(string.Format(CacheKey.CUSTOMERGROUPSPRODUCTS_ROLE_KEY, customerGroupProduct.CustomerGroupId));

            await _cacheBase.RemoveByPrefix(CacheKey.PRODUCTS_CUSTOMER_GROUP_PATTERN);

            //event notification
            await _mediator.EntityInserted(customerGroupProduct);
        }
Пример #2
0
        public virtual async Task InsertProductModel(CustomerGroupProductModel.AddProductModel model)
        {
            foreach (string id in model.SelectedProductIds)
            {
                var product = await _productService.GetProductById(id);

                if (product != null)
                {
                    var customerGroupProduct = await _customerGroupProductService.GetCustomerGroupProduct(model.CustomerGroupId, id);

                    if (customerGroupProduct == null)
                    {
                        customerGroupProduct = new CustomerGroupProduct();
                        customerGroupProduct.CustomerGroupId = model.CustomerGroupId;
                        customerGroupProduct.ProductId       = id;
                        customerGroupProduct.DisplayOrder    = 0;
                        await _customerGroupProductService.InsertCustomerGroupProduct(customerGroupProduct);
                    }
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Updates the customer group product
        /// </summary>
        /// <param name="customerGroupProduct">Customer group product</param>
        public virtual async Task UpdateCustomerGroupProduct(CustomerGroupProduct customerGroupProduct)
        {
            if (customerGroupProduct == null)
            {
                throw new ArgumentNullException(nameof(customerGroupProduct));
            }

            var builder = Builders <CustomerGroupProduct> .Filter;
            var filter  = builder.Eq(x => x.Id, customerGroupProduct.Id);
            var update  = Builders <CustomerGroupProduct> .Update
                          .Set(x => x.DisplayOrder, customerGroupProduct.DisplayOrder);

            await _customerGroupProductRepository.Collection.UpdateOneAsync(filter, update);

            //clear cache
            await _cacheBase.RemoveAsync(string.Format(CacheKey.CUSTOMERGROUPSPRODUCTS_ROLE_KEY, customerGroupProduct.CustomerGroupId));

            await _cacheBase.RemoveByPrefix(CacheKey.PRODUCTS_CUSTOMER_GROUP_PATTERN);

            //event notification
            await _mediator.EntityUpdated(customerGroupProduct);
        }