/// <summary> /// Creates a new Radio control. /// </summary> /// <param name="requestContext">The request helper.</param> /// <param name="model">The current model.</param> /// <param name="metadata">The model metadata.</param> public FWRadioControl(FWRequestContext requestContext, object model, ModelMetadata metadata) : base(requestContext, model, metadata) { if (FWReflectionHelper.CheckType <bool>(metadata.ModelType)) { _isBoolean = true; _values = new Dictionary <string, string> { { "true", GetModelResource("TRUE") }, { "false", GetModelResource("FALSE") } }; if (model != null) { _selected = model.ToString(); } } else if (FWReflectionHelper.IsEnum(metadata.ModelType)) { var enumDictionary = FWEnumHelper.GetEnumAsDictonary(metadata.ModelType); _values = new Dictionary <string, string>(); // Gets the resource values for the enum items. foreach (var item in enumDictionary) { _values.Add(item.Key, GetModelResource(item.Value)); } _selected = FWEnumHelper.GetValues(model as Enum).FirstOrDefault(); } else { throw new FWMissingDatasourceException(Id); } }
/// <summary> /// Creates a new Checkbox control. /// </summary> /// <param name="requestContext">The request helper.</param> /// <param name="model">The current model.</param> /// <param name="metadata">The model metadata.</param> public FWCheckboxControl(FWRequestContext requestContext, object model, ModelMetadata metadata) : base(requestContext, model, metadata) { if (FWReflectionHelper.CheckType <bool>(metadata.ModelType)) { _isBoolean = true; _values = new Dictionary <string, string> { { "true", DisplayName } }; if (model != null) { _selected.Add(model.ToString()); } //If the property is boolean, there is no sense in being required. if (metadata.ModelType == FWKnownTypes.Bool) { IsRequired = false; } HideLabel(); } else if (FWReflectionHelper.IsEnum(metadata.ModelType)) { var enumDictionary = FWEnumHelper.GetEnumAsDictonary(metadata.ModelType); _values = new Dictionary <string, string>(); // Gets the resource values for the enum items. foreach (var item in enumDictionary) { _values.Add(item.Key, GetModelResource(item.Value)); } _selected = FWEnumHelper.GetValues(model as Enum).ToList(); } else { throw new FWMissingDatasourceException(Id); } }