/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Property ToDataModel(this coreModel.Property property) { if (property == null) throw new ArgumentNullException("property"); var retVal = new dataModel.Property(); retVal.InjectFrom(property); retVal.PropertyValueType = (int)property.ValueType; retVal.IsMultiValue = property.Multivalue; retVal.IsLocaleDependant = property.Multilanguage; retVal.IsEnum = property.Dictionary; retVal.IsRequired = property.Required; retVal.TargetType = property.Type.ToString(); if (property.Attributes != null) { retVal.PropertyAttributes = new ObservableCollection<dataModel.PropertyAttribute>(); foreach (var attribute in property.Attributes) { var dbAttribute = attribute.ToDataModel(); retVal.PropertyAttributes.Add(dbAttribute); } } if (property.DictionaryValues != null) { retVal.DictionaryValues = new ObservableCollection<dataModel.PropertyDictionaryValue>(); foreach (var dictValue in property.DictionaryValues) { var dbDictValue = dictValue.ToDataModel(); retVal.DictionaryValues.Add(dbDictValue); } } if (property.DisplayNames != null) { foreach (var displayName in property.DisplayNames.Where(x=> !String.IsNullOrEmpty(x.Name))) { var attributeName = "DisplayName" + displayName.LanguageCode; var existAttribute = retVal.PropertyAttributes.FirstOrDefault(x => x.PropertyAttributeName == attributeName); if(existAttribute == null) { existAttribute = new dataModel.PropertyAttribute { PropertyId = property.Id, PropertyAttributeName = attributeName, }; retVal.PropertyAttributes.Add(existAttribute); } existAttribute.PropertyAttributeValue = displayName.Name; } } return retVal; }
public void SetCategoryProperty(dataModel.Category category, dataModel.Property property) { if (category.PropertySet == null) { var propertySet = new dataModel.PropertySet { Name = category.Name + " property set", TargetType = "Category" }; Add(propertySet); category.PropertySetId = propertySet.Id; } var propertySetProperty = new dataModel.PropertySetProperty { PropertySetId = category.PropertySetId, PropertyId = property.Id }; Add(propertySetProperty); }
/// <summary> /// Converting to model type /// </summary> /// <param name="catalogBase"></param> /// <returns></returns> public static coreModel.Property ToCoreModel(this dataModel.Property dbProperty, dataModel.Catalog[] allCatalogs, dataModel.Category[] allCategories) { if (dbProperty == null) { throw new ArgumentNullException("dbProperty"); } var retVal = new coreModel.Property(); retVal.CatalogId = dbProperty.CatalogId; retVal.CategoryId = dbProperty.CategoryId; retVal.CreatedBy = dbProperty.CreatedBy; retVal.CreatedDate = dbProperty.CreatedDate; retVal.Id = dbProperty.Id; retVal.ModifiedBy = dbProperty.ModifiedBy; retVal.ModifiedDate = dbProperty.ModifiedDate; retVal.Name = dbProperty.Name; retVal.Required = dbProperty.IsRequired; retVal.Multivalue = dbProperty.IsMultiValue; retVal.Multilanguage = dbProperty.IsLocaleDependant; retVal.Dictionary = dbProperty.IsEnum; retVal.ValueType = (coreModel.PropertyValueType)dbProperty.PropertyValueType; retVal.Catalog = allCatalogs.First(x => x.Id == dbProperty.CatalogId).ToCoreModel(convertProps: false); if (dbProperty.CategoryId != null) { retVal.Category = allCategories.First(x => x.Id == dbProperty.CategoryId) .ToCoreModel(allCatalogs, allCategories, convertProps: false); } coreModel.PropertyType propertyType; if (!string.IsNullOrEmpty(dbProperty.TargetType) && Enum.TryParse(dbProperty.TargetType, out propertyType)) { retVal.Type = propertyType; } retVal.DisplayNames = retVal.Catalog.Languages.Select(x => new PropertyDisplayName { LanguageCode = x.LanguageCode }).ToList(); if (dbProperty.PropertyAttributes != null) { retVal.Attributes = new List <coreModel.PropertyAttribute>(); retVal.Attributes.AddRange(dbProperty.PropertyAttributes.Select(x => x.ToCoreModel(retVal))); //Load display names from attributes foreach (var displayNameAttribute in retVal.Attributes.Where(x => x.Name.StartsWith("DisplayName"))) { var languageCode = displayNameAttribute.Name.Substring("DisplayName".Length); var displayName = retVal.DisplayNames.FirstOrDefault(x => String.Equals(x.LanguageCode, languageCode, StringComparison.InvariantCultureIgnoreCase)); if (displayName != null) { displayName.Name = displayNameAttribute.Value; } } } if (dbProperty.DictionaryValues != null) { retVal.DictionaryValues = new List <coreModel.PropertyDictionaryValue>(); retVal.DictionaryValues.AddRange(dbProperty.DictionaryValues.Select(x => x.ToCoreModel())); } return(retVal); }
/// <summary> /// Converting to foundation type /// </summary> /// <param name="catalog"></param> /// <returns></returns> public static dataModel.Property ToDataModel(this coreModel.Property property) { if (property == null) { throw new ArgumentNullException("property"); } var retVal = new dataModel.Property(); var id = retVal.Id; retVal.InjectFrom(property); if (property.Id == null) { retVal.Id = id; } retVal.PropertyValueType = (int)property.ValueType; retVal.IsMultiValue = property.Multivalue; retVal.IsLocaleDependant = property.Multilanguage; retVal.IsEnum = property.Dictionary; retVal.IsRequired = property.Required; retVal.TargetType = property.Type.ToString(); if (property.Attributes != null) { retVal.PropertyAttributes = new ObservableCollection <dataModel.PropertyAttribute>(); foreach (var attribute in property.Attributes) { var dbAttribute = attribute.ToDataModel(); retVal.PropertyAttributes.Add(dbAttribute); } } if (property.DictionaryValues != null) { retVal.PropertyValues = new ObservableCollection <dataModel.PropertyValue>(); foreach (var dictValue in property.DictionaryValues) { var dbDictValue = dictValue.ToDataModel(property); retVal.PropertyValues.Add(dbDictValue); } } if (property.DisplayNames != null) { foreach (var displayName in property.DisplayNames.Where(x => !String.IsNullOrEmpty(x.Name))) { var attributeName = "DisplayName" + displayName.LanguageCode; var existAttribute = retVal.PropertyAttributes.FirstOrDefault(x => x.PropertyAttributeName == attributeName); if (existAttribute == null) { existAttribute = new dataModel.PropertyAttribute { PropertyId = property.Id, PropertyAttributeName = attributeName, }; retVal.PropertyAttributes.Add(existAttribute); } existAttribute.PropertyAttributeValue = displayName.Name; } } return(retVal); }