public void Can_save_and_load_customerAttribute_with_values() { var ca = new CustomerAttribute() { Name = "Name 1", IsRequired = true, AttributeControlType = AttributeControlType.Datepicker, DisplayOrder = 2 }; ca.CustomerAttributeValues.Add ( new CustomerAttributeValue() { Name = "Name 2", IsPreSelected = true, DisplayOrder = 1, } ); var fromDb = SaveAndLoadEntity(ca); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Name 1"); fromDb.CustomerAttributeValues.ShouldNotBeNull(); (fromDb.CustomerAttributeValues.Count == 1).ShouldBeTrue(); fromDb.CustomerAttributeValues.First().Name.ShouldEqual("Name 2"); }
protected virtual void UpdateAttributeLocales(CustomerAttribute customerAttribute, CustomerAttributeModel model) { foreach (var localized in model.Locales) { _localizedEntityService.SaveLocalizedValue(customerAttribute, x => x.Name, localized.Name, localized.LanguageId); } }
public void Can_save_and_load_customerAttribute() { var customerAttribute = new CustomerAttribute { Key = "Key 1", Value = "Value 1", Customer = GetTestCustomer() }; var fromDb = SaveAndLoadEntity(customerAttribute); fromDb.ShouldNotBeNull(); fromDb.Key.ShouldEqual("Key 1"); fromDb.Value.ShouldEqual("Value 1"); fromDb.Customer.ShouldNotBeNull(); }
public void Can_save_and_load_customerAttribute() { var ca = new CustomerAttribute() { Name = "Name 1", IsRequired = true, AttributeControlType = AttributeControlType.Datepicker, DisplayOrder = 2 }; var fromDb = SaveAndLoadEntity(ca); fromDb.ShouldNotBeNull(); fromDb.Name.ShouldEqual("Name 1"); fromDb.IsRequired.ShouldEqual(true); fromDb.AttributeControlType.ShouldEqual(AttributeControlType.Datepicker); fromDb.DisplayOrder.ShouldEqual(2); }
/// <summary> /// Adds an attribute /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <param name="ca">Customer attribute</param> /// <param name="value">Value</param> /// <returns>Attributes</returns> public virtual string AddCustomerAttribute(string attributesXml, CustomerAttribute ca, string value) { string result = string.Empty; try { var xmlDoc = new XmlDocument(); if (String.IsNullOrEmpty(attributesXml)) { var element1 = xmlDoc.CreateElement("Attributes"); xmlDoc.AppendChild(element1); } else { xmlDoc.LoadXml(attributesXml); } var rootElement = (XmlElement)xmlDoc.SelectSingleNode(@"//Attributes"); XmlElement attributeElement = null; //find existing var nodeList1 = xmlDoc.SelectNodes(@"//Attributes/CustomerAttribute"); foreach (XmlNode node1 in nodeList1) { if (node1.Attributes != null && node1.Attributes["ID"] != null) { string str1 = node1.Attributes["ID"].InnerText.Trim(); int id; if (int.TryParse(str1, out id)) { if (id == ca.Id) { attributeElement = (XmlElement)node1; break; } } } } //create new one if not found if (attributeElement == null) { attributeElement = xmlDoc.CreateElement("CustomerAttribute"); attributeElement.SetAttribute("ID", ca.Id.ToString()); rootElement.AppendChild(attributeElement); } var attributeValueElement = xmlDoc.CreateElement("CustomerAttributeValue"); attributeElement.AppendChild(attributeValueElement); var attributeValueValueElement = xmlDoc.CreateElement("Value"); attributeValueValueElement.InnerText = value; attributeValueElement.AppendChild(attributeValueValueElement); result = xmlDoc.OuterXml; } catch (Exception exc) { Debug.Write(exc.ToString()); } return result; }
/// <summary> /// Deletes a customer attribute /// </summary> /// <param name="customerAttribute">Customer attribute</param> public virtual void DeleteCustomerAttribute(CustomerAttribute customerAttribute) { if (customerAttribute == null) throw new ArgumentNullException("customerAttribute"); _customerAttributeRepository.Delete(customerAttribute); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTES_PATTERN_KEY); _cacheManager.RemoveByPattern(CUSTOMERATTRIBUTEVALUES_PATTERN_KEY); //event notification _eventPublisher.EntityDeleted(customerAttribute); }
public static CustomerAttribute ToEntity(this CustomerAttributeModel model, CustomerAttribute destination) { return Mapper.Map(model, destination); }
protected virtual List<LocalizedProperty> UpdateAttributeLocales(CustomerAttribute customerAttribute, CustomerAttributeModel model) { List<LocalizedProperty> localized = new List<LocalizedProperty>(); foreach (var local in model.Locales) { if (!(String.IsNullOrEmpty(local.Name))) localized.Add(new LocalizedProperty() { LanguageId = local.LanguageId, LocaleKey = "Name", LocaleValue = local.Name }); } return localized; }