Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
 public static IHasCustomProperties AddCustomProperties(this IHasCustomProperties obj, HashSet <CustomProperty> customProperties)
 {
     customProperties.ForEach(cp => obj.CustomProperties.Add(cp));
     return(obj);
 }