/// <summary> /// Updates the customer attribute /// </summary> /// <param name="customerAttribute">Customer attribute</param> public void UpdateCustomerAttribute(CustomerAttribute customerAttribute) { if (customerAttribute == null) throw new ArgumentNullException("customerAttribute"); if (customerAttribute.CustomerId == 0) throw new NopException("Cannot insert attribute for non existing customer"); customerAttribute.Key = CommonHelper.EnsureNotNull(customerAttribute.Key); customerAttribute.Key = CommonHelper.EnsureMaximumLength(customerAttribute.Key, 100); customerAttribute.Value = CommonHelper.EnsureNotNull(customerAttribute.Value); customerAttribute.Value = CommonHelper.EnsureMaximumLength(customerAttribute.Value, 1000); if (!_context.IsAttached(customerAttribute)) _context.CustomerAttributes.Attach(customerAttribute); _context.SaveChanges(); }
/// <summary> /// Inserts a customer attribute /// </summary> /// <param name="customerAttribute">Customer attribute</param> public void InsertCustomerAttribute(CustomerAttribute customerAttribute) { if (customerAttribute == null) throw new ArgumentNullException("customerAttribute"); if (customerAttribute.CustomerId == 0) throw new NopException("Cannot insert attribute for non existing customer"); if (customerAttribute.Value == null) customerAttribute.Value = string.Empty; customerAttribute.Key = CommonHelper.EnsureNotNull(customerAttribute.Key); customerAttribute.Key = CommonHelper.EnsureMaximumLength(customerAttribute.Key, 100); customerAttribute.Value = CommonHelper.EnsureNotNull(customerAttribute.Value); customerAttribute.Value = CommonHelper.EnsureMaximumLength(customerAttribute.Value, 1000); _context.CustomerAttributes.AddObject(customerAttribute); _context.SaveChanges(); }