void PrepareCatalog(IHasCustomProperties <List <SelectListItem> > model) { var list = _context.Catalog.OrderByDescending(x => x.Id).ToList(); var items = list.ToSelectListItem(item => new SelectListItem { Text = item.Title, Value = item.Id.ToString() }, true); model.CustomProperties.Add(PropertiesKey.Key_1, items); }
public static object GetCustomPropertyValue(this IHasCustomProperties obj, string name) { var property = obj.CustomProperties.SingleOrDefault(x => x.Definition.Value == name); if (property == null) { throw new ArgumentException($"Property {name} not found"); } return(property.Value); }
public static void AdoptValues(this IHasCustomProperties obj, KeyValuePair <string, object> propertyValue) { var existing = obj.CustomProperties.SingleOrDefault(x => x.Definition.Value == propertyValue.Key); if (existing == null) { return; } existing.Value = existing.Definition.ConvertThenValidate(propertyValue.Value); }
public static IHasCustomProperties SetCustomProperty(this IHasCustomProperties obj, CustomProperty customProperty) { var existing = obj.CustomProperties.SingleOrDefault(x => x.Definition.Value == customProperty.Definition.Value); if (existing != null) { existing.Value = customProperty.Value; } else { obj.CustomProperties.Add(customProperty); } return(obj); }
public static IHasCustomProperties AddCustomProperties(this IHasCustomProperties obj, HashSet <CustomProperty> customProperties) { customProperties.ForEach(cp => obj.CustomProperties.Add(cp)); return(obj); }