Beispiel #1
0
        /// <inheritdoc />
        public IEnumerable <KeyValuePair <string, string> > GetById(Guid id)
        {
            var items     = new List <KeyValuePair <string, string> >();
            var dataValue = DataValues.Retrieve(id);

            if (dataValue == null)
            {
                return(items);
            }

            // Extract list items from the data value.
            var kind = DataValueKindCollection.FirstOrDefault(x => x.Id == dataValue.KindId);

            // Check type of collection returned by the data value kind.
            if (kind is IGetValueAndLabelCollection pairCollection)
            {
                // Create drop down items from values and labels.
                var pairs = pairCollection.GetValues(dataValue.Data);
                items.AddRange(pairs.Select(x => new KeyValuePair <string, string>(x.Label, x.Value)));
            }
            else if (kind is IGetStringCollection stringCollection)
            {
                // Create drop down items from strings.
                var strings = stringCollection.GetValues(dataValue.Data);
                items.AddRange(strings.Select(x => new KeyValuePair <string, string>(x, x)));
            }

            return(items);
        }
        /// <summary>
        /// Deserialize the configuration for a checkbox list field.
        /// </summary>
        /// <param name="configuration">
        /// The serialized configuration.
        /// </param>
        /// <returns>
        /// The deserialized configuration.
        /// </returns>
        public object DeserializeConfiguration(string configuration)
        {
            // Variables.
            var items  = new List <CheckboxListItem>();
            var config = new CheckboxListConfiguration()
            {
                Items = items
            };
            var configData    = JsonHelper.Deserialize <JObject>(configuration);
            var dynamicConfig = configData as dynamic;
            var properties    = configData.Properties().Select(x => x.Name);
            var propertySet   = new HashSet <string>(properties);


            // A data value is selected?
            if (propertySet.Contains("dataValue"))
            {
                // Get info about the data value.
                var dataValueId = GuidHelper.GetGuid(dynamicConfig.dataValue.Value as string);
                var dataValue   = DataValues.Retrieve(dataValueId);
                if (dataValue != null)
                {
                    // Extract list items from the data value.
                    var kind             = DataValueKindCollection.FirstOrDefault(x => x.Id == dataValue.KindId);
                    var pairCollection   = kind as IGetValueAndLabelCollection;
                    var stringCollection = kind as IGetStringCollection;


                    // Check type of collection returned by the data value kind.
                    if (pairCollection != null)
                    {
                        // Create checkboxes from values and labels.
                        var pairs = pairCollection.GetValues(dataValue.Data);
                        items.AddRange(pairs.Select(x => new CheckboxListItem()
                        {
                            Selected = false,
                            Value    = x.Value,
                            Label    = x.Label
                        }));
                    }
                    else if (stringCollection != null)
                    {
                        // Create checkboxes from strings.
                        var strings = stringCollection.GetValues(dataValue.Data);
                        items.AddRange(strings.Select(x => new CheckboxListItem()
                        {
                            Selected = false,
                            Value    = x,
                            Label    = x
                        }));
                    }
                }
            }


            // Return the data value configuration.
            return(config);
        }
 /// <summary>
 /// Gets the entity with the specified ID.
 /// </summary>
 /// <param name="entityId">The ID of the entity.</param>
 /// <returns>
 /// The entity.
 /// </returns>
 public IEntity Retrieve(Guid entityId)
 {
     // Root-level node?
     if (EntityHelper.IsRoot(entityId))
     {
         return(new EntityRoot()
         {
             Id = entityId,
             Path = new[] { entityId },
             Name = EntityHelper.GetNameForRoot(entityId),
             Icon = EntityHelper.GetIconForRoot(entityId)
         });
     }
     else
     {
         // Specific entities (e.g., forms or layouts).
         return(Folders.Retrieve(entityId) as IEntity
                ?? Forms.Retrieve(entityId) as IEntity
                ?? ConfiguredForms.Retrieve(entityId) as IEntity
                ?? Layouts.Retrieve(entityId) as IEntity
                ?? Validations.Retrieve(entityId) as IEntity
                ?? DataValues.Retrieve(entityId) as IEntity);
     }
 }