Ejemplo n.º 1
0
        /// <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 kinds            = DataValueHelper.GetAllDataValueKinds();
                    var kind             = kinds.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);
        }
Ejemplo n.º 2
0
        /// <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 kinds = DataValueHelper.GetAllDataValueKinds();
                    var kind = kinds.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;
        }