Exemplo n.º 1
0
        public static void SaveCustomerAttribute <TPropType>(this Customer customer, string key, TPropType value,
                                                             ICustomerAttributeService _customerAttributeService)
        {
            if (customer == null || customer.Id == 0)
            {
                throw new ArgumentNullException("customer");
            }

            var props     = _customerAttributeService.GetAttributeByCustomerId(customer.Id);
            var attribute = new CustomerAttribute();

            if (props != null &&
                props.Count > 0 &&
                props.FirstOrDefault(ga =>
                                     ga.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase)) != null)
            {
                attribute = props.FirstOrDefault(ga =>
                                                 ga.Key.Equals(key, StringComparison.InvariantCultureIgnoreCase));

                attribute.Value = value.ToString();
            }
            else
            {
                attribute.CustomerId = customer.Id;
                attribute.Key        = key;
                attribute.Value      = value.ToString();
            }
            _customerAttributeService.SaveAttribute(attribute);
        }