/// <summary> /// Based on selected Stat type get the stat properties that need to be rendered inside the ActivityUI so the user can put values for them /// </summary> /// <param name="statType"></param> /// <returns></returns> public static List <PropertyInfo> GetStatTypeProperties(string statType) { var statTypeProperties = new List <PropertyInfo>(); BaseStatDTO stat; switch (statType) { case StatTypes.Number: stat = new NumberStatDTO(); break; case StatTypes.Range: stat = new RangeStatDTO(); break; case StatTypes.CheckList: stat = new CheckListStatDTO(); break; case StatTypes.HorizontalBars: stat = new HorizontalBarsStatDTO(); break; case StatTypes.PickList: stat = new PicklistStatDTO(); break; default: return(statTypeProperties); } return(stat.GetType().GetProperties().Where(prop => prop.IsDefined(typeof(RenderUiPropertyAttribute), false)).ToList()); }
/// <summary> /// For a selected stat type create a child instance of BaseStatDTO and populate all properties with values based on what user has chose in the activity /// </summary> /// <param name="statType"></param> /// <param name="statProperties">Key value pairs for all available stat properties based on type with name of property and value for it</param> /// <param name="statItems">Key value pair for stat types that has items collection proeperty</param> /// <returns></returns> public static BaseStatDTO CreateStatFromDynamicStatProperties(string statType, List <KeyValueDTO> statProperties, List <KeyValueDTO> statItems) { BaseStatDTO stat; switch (statType) { case StatTypes.Number: stat = new NumberStatDTO(); PopulateStatObject(stat, statProperties); break; case StatTypes.Range: stat = new RangeStatDTO(); PopulateStatObject(stat, statProperties); break; case StatTypes.CheckList: stat = new CheckListStatDTO(); PopulateStatObject(stat, statProperties); foreach (var statItem in statItems) { ((CheckListStatDTO)stat).Items.Add(new CheckListItemDTO() { Name = statItem.Key, Checked = ConvertChecklistItemValue(statItem.Value) }); } break; case StatTypes.HorizontalBars: stat = new HorizontalBarsStatDTO { DynamicJsonIgnoreProperties = new[] { "checked" } }; PopulateStatObject(stat, statProperties); ((HorizontalBarsStatDTO)stat).Items = statItems.Select(x => new StatItemValueDTO() { Name = x.Key, Value = x.Value }).ToList(); break; case StatTypes.PickList: stat = new PicklistStatDTO { DynamicJsonIgnoreProperties = new[] { "value" } }; PopulateStatObject(stat, statProperties); ((PicklistStatDTO)stat).Items = statItems.Select(x => new PicklistItemDTO() { Name = x.Key, Color = string.IsNullOrEmpty(x.Value) ? "UNKNOWN" : x.Value.ToUpper() }).ToList(); break; default: return(new BaseStatDTO()); } return(stat); }