public PropertiesEntry GetPropertiesEntry() { var key = Key.Replace("-", "."); var propertiesSet = PropertiesProvider.GetInstance(key); var entry = new PropertiesEntry(key); var propertiesValues = new List <PropertiesValue>(); foreach (var propertiesElement in Properties) { var property = propertiesSet.GetType().GetProperty(propertiesElement.Key.Replace("-", ".")); if (property != null) { foreach (var propertyValue in propertiesElement.Values) { var value = ParsePropertyValue(property.PropertyType, propertyValue.Value); var propertiesValue = propertiesValues.FirstOrDefault(v => v.SiteId == propertyValue.SiteId); if (propertiesValue == null) { propertiesValue = new PropertiesValue(propertyValue.SiteId, PropertiesProvider.GetInstance(key)); propertiesValues.Add(propertiesValue); } property.SetValue(propertiesValue.Value, value); } } } entry.Properties.AddRange(propertiesValues); return(entry); }
public static PropertiesGroup Create(PropertiesEntry propertiesEntry, PropertiesSchema schema) { var restModel = new PropertiesGroup(schema.Name, schema.Key.Replace(".", "-"), schema.IsEditable, schema.Mode); foreach (var propertyInfo in schema.Properties) { var values = new List <PropertiesElementValue>(); foreach (var propertiesValue in propertiesEntry.Properties) { var value = propertiesValue.Value.GetType().GetProperty(propertyInfo.Key)?.GetValue(propertiesValue.Value, null); values.Add(new PropertiesElementValue(propertiesValue.SiteId, value)); } var property = new PropertiesElement(propertyInfo.Key.Replace(".", "-"), propertyInfo.Name, propertyInfo.Type, values, propertyInfo.IsRequired); restModel.Properties.Add(property); } return(restModel); }