/// <summary> /// Deserialize the configuration for a drop down field. /// </summary> /// <param name="configuration"> /// The serialized configuration. /// </param> /// <returns> /// The deserialized configuration. /// </returns> public object DeserializeConfiguration(string configuration) { // Variables. var items = new List <DropDownItem>(); var config = new DropDownConfiguration() { 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 drop down items from values and labels. var pairs = pairCollection.GetValues(dataValue.Data); items.AddRange(pairs.Select(x => new DropDownItem() { Selected = false, Value = x.Value, Label = x.Label })); } else if (stringCollection != null) { // Create drop down items from strings. var strings = stringCollection.GetValues(dataValue.Data); items.AddRange(strings.Select(x => new DropDownItem() { Selected = false, Value = x, Label = x })); } } } // Return the data value configuration. return(config); }
/// <summary> /// Deserialize the configuration for a drop down field. /// </summary> /// <param name="configuration"> /// The serialized configuration. /// </param> /// <returns> /// The deserialized configuration. /// </returns> public object DeserializeConfiguration(string configuration) { // Variables. var items = new List <DropDownItem>(); var config = new DropDownConfiguration() { 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 strItems = kind is DataValueList?ExtractList(dataValue.Data) : new List <string>(); items.AddRange(strItems.Select(x => new DropDownItem() { Label = x, Selected = false, Value = x })); } } // Return the data value configuration. return(config); }
/// <summary> /// Deserialize the configuration for a drop down field. /// </summary> /// <param name="configuration"> /// The serialized configuration. /// </param> /// <returns> /// The deserialized configuration. /// </returns> public object DeserializeConfiguration(string configuration) { // Variables. var items = new List<DropDownItem>(); var config = new DropDownConfiguration() { 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 drop down items from values and labels. var pairs = pairCollection.GetValues(dataValue.Data); items.AddRange(pairs.Select(x => new DropDownItem() { Selected = false, Value = x.Value, Label = x.Label })); } else if (stringCollection != null) { // Create drop down items from strings. var strings = stringCollection.GetValues(dataValue.Data); items.AddRange(strings.Select(x => new DropDownItem() { Selected = false, Value = x, Label = x })); } } } // Return the data value configuration. return config; }