protected bool ConditionCategory(CustomerAction.ActionCondition condition, ICollection <ProductCategory> categorties)
        {
            bool cond = true;

            if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
            {
                cond = categorties.Select(x => x.CategoryId).ContainsAll(condition.Categories);
            }
            if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
            {
                cond = categorties.Select(x => x.CategoryId).ContainsAny(condition.Categories);
            }

            return(cond);
        }
Ejemplo n.º 2
0
        protected bool ConditionProducts(CustomerAction.ActionCondition condition, ICollection <string> products)
        {
            bool cond = true;

            if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
            {
                cond = products.ContainsAll(condition.Products);
            }
            if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
            {
                cond = products.ContainsAny(condition.Products);
            }

            return(cond);
        }
Ejemplo n.º 3
0
        protected bool ConditionManufacturer(CustomerAction.ActionCondition condition, ICollection <string> manufacturers)
        {
            bool cond = true;

            if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
            {
                cond = manufacturers.ContainsAll(condition.Manufacturers);
            }
            if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
            {
                cond = manufacturers.ContainsAny(condition.Manufacturers);
            }

            return(cond);
        }
Ejemplo n.º 4
0
        protected bool ConditionManufacturer(CustomerAction.ActionCondition condition, ICollection <ProductManufacturer> manufacturers)
        {
            bool cond = true;

            if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
            {
                cond = manufacturers.Select(x => x.ManufacturerId).ContainsAll(condition.Manufacturers);
            }
            if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
            {
                cond = manufacturers.Select(x => x.ManufacturerId).ContainsAny(condition.Manufacturers);
            }

            return(cond);
        }
Ejemplo n.º 5
0
        protected bool ConditionCategory(CustomerAction.ActionCondition condition, ICollection <string> categorties)
        {
            bool cond = true;

            if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
            {
                cond = categorties.ContainsAll(condition.Categories);
            }
            if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
            {
                cond = categorties.ContainsAny(condition.Categories);
            }

            return(cond);
        }
Ejemplo n.º 6
0
        protected bool ConditionCustomerTag(CustomerAction.ActionCondition condition, Customer customer)
        {
            bool cond = false;

            if (customer != null)
            {
                var customerTags = customer.CustomerTags;
                if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
                {
                    cond = customerTags.Select(x => x).ContainsAll(condition.CustomerTags);
                }
                if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
                {
                    cond = customerTags.Select(x => x).ContainsAny(condition.CustomerTags);
                }
            }
            return(cond);
        }
        public virtual (string customerActionId, string conditionId) InsertCustomerActionConditionModel(CustomerActionConditionModel model)
        {
            var customerAction = _customerActionService.GetCustomerActionById(model.CustomerActionId);

            if (customerAction == null)
            {
                return(null, null);
            }
            var condition = new CustomerAction.ActionCondition()
            {
                Name = model.Name,
                CustomerActionConditionTypeId = model.CustomerActionConditionTypeId,
                ConditionId = model.ConditionId,
            };

            customerAction.Conditions.Add(condition);
            _customerActionService.UpdateCustomerAction(customerAction);

            _customerActivityService.InsertActivity("AddNewCustomerActionCondition", customerAction.Id, _localizationService.GetResource("ActivityLog.AddNewCustomerAction"), customerAction.Name);
            return(customerAction.Id, condition.Id);
        }
Ejemplo n.º 8
0
        protected async Task <bool> ConditionCustomerAttribute(CustomerAction.ActionCondition condition, Customer customer)
        {
            bool cond = false;

            if (customer != null)
            {
                var customerAttributeParser = _serviceProvider.GetRequiredService <ICustomerAttributeParser>();

                var _genericAttributes = customer.GenericAttributes;
                if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
                {
                    var customCustomerAttributes = _genericAttributes.FirstOrDefault(x => x.Key == "CustomCustomerAttributes");
                    if (customCustomerAttributes != null)
                    {
                        if (!String.IsNullOrEmpty(customCustomerAttributes.Value))
                        {
                            var selectedValues = await customerAttributeParser.ParseCustomerAttributeValues(customCustomerAttributes.Value);

                            cond = true;
                            foreach (var item in condition.CustomCustomerAttributes)
                            {
                                var _fields = item.RegisterField.Split(':');
                                if (_fields.Count() > 1)
                                {
                                    if (selectedValues.Where(x => x.CustomerAttributeId == _fields.FirstOrDefault() && x.Id == _fields.LastOrDefault()).Count() == 0)
                                    {
                                        cond = false;
                                    }
                                }
                                else
                                {
                                    cond = false;
                                }
                            }
                        }
                    }
                }
                if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
                {
                    var customCustomerAttributes = _genericAttributes.FirstOrDefault(x => x.Key == "CustomCustomerAttributes");
                    if (customCustomerAttributes != null)
                    {
                        if (!String.IsNullOrEmpty(customCustomerAttributes.Value))
                        {
                            var selectedValues = await customerAttributeParser.ParseCustomerAttributeValues(customCustomerAttributes.Value);

                            foreach (var item in condition.CustomCustomerAttributes)
                            {
                                var _fields = item.RegisterField.Split(':');
                                if (_fields.Count() > 1)
                                {
                                    if (selectedValues.Where(x => x.CustomerAttributeId == _fields.FirstOrDefault() && x.Id == _fields.LastOrDefault()).Count() > 0)
                                    {
                                        cond = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(cond);
        }
Ejemplo n.º 9
0
 protected bool ConditionVendors(CustomerAction.ActionCondition condition, string vendorId)
 {
     return(condition.Vendors.Contains(vendorId));
 }
Ejemplo n.º 10
0
        protected bool ConditionProductAttribute(CustomerAction.ActionCondition condition, Product product, string AttributesXml)
        {
            bool cond = false;
            var  productAttributeParser = _serviceProvider.GetRequiredService <IProductAttributeParser>();

            if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
            {
                var attributes = productAttributeParser.ParseProductAttributeMappings(product, AttributesXml);
                foreach (var attr in attributes)
                {
                    var attributeValuesStr = productAttributeParser.ParseValues(AttributesXml, attr.Id);
                    foreach (var attrV in attributeValuesStr)
                    {
                        var attrsv = attr.ProductAttributeValues.Where(x => x.Id == attrV).FirstOrDefault();
                        if (attrsv != null)
                        {
                            if (condition.ProductAttribute.Where(x => x.ProductAttributeId == attr.ProductAttributeId && x.Name == attrsv.Name).Count() > 0)
                            {
                                cond = true;
                            }
                        }
                    }
                }
            }
            if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
            {
                cond = true;
                foreach (var itemPA in condition.ProductAttribute)
                {
                    var attributes = productAttributeParser.ParseProductAttributeMappings(product, AttributesXml);
                    if (attributes.Where(x => x.ProductAttributeId == itemPA.ProductAttributeId).Count() > 0)
                    {
                        cond = false;
                        foreach (var attr in attributes.Where(x => x.ProductAttributeId == itemPA.ProductAttributeId))
                        {
                            var attributeValuesStr = productAttributeParser.ParseValues(AttributesXml, attr.Id);
                            foreach (var attrV in attributeValuesStr)
                            {
                                var attrsv = attr.ProductAttributeValues.Where(x => x.Id == attrV).FirstOrDefault();
                                if (attrsv != null)
                                {
                                    if (attrsv.Name == itemPA.Name)
                                    {
                                        cond = true;
                                    }
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                        if (!cond)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }

            return(cond);
        }
Ejemplo n.º 11
0
 protected bool ConditionStores(CustomerAction.ActionCondition condition, string storeId)
 {
     return(condition.Stores.Contains(storeId));
 }
Ejemplo n.º 12
0
 protected bool ConditionProducts(CustomerAction.ActionCondition condition, string productId)
 {
     return(condition.Products.Contains(productId));
 }
Ejemplo n.º 13
0
 public static CustomerAction.ActionCondition ToEntity(this CustomerActionConditionModel model, CustomerAction.ActionCondition destination)
 {
     return(model.MapTo(destination));
 }
Ejemplo n.º 14
0
 public static CustomerActionConditionModel ToModel(this CustomerAction.ActionCondition entity)
 {
     return(entity.MapTo <CustomerAction.ActionCondition, CustomerActionConditionModel>());
 }