Пример #1
0
        /// <summary>
        /// Creates the framework control.
        /// </summary>
        /// <param name="context">Contains information associated with the current HTML tag.</param>
        /// <param name="output">A stateful HTML element used to generate an HTML tag.</param>
        /// <returns>The control instance.</returns>
        protected override IFWHtmlElement RenderControl(TagHelperContext context, TagHelperOutput output)
        {
            if (!FWReflectionHelper.IsCollection(For.Metadata.ModelType))
            {
                throw new FWInvalidModelException("Invalid model for detail. Must use a collection.");
            }

            FWControl control = null;

            switch (Type)
            {
            case FWDetailType.Table:
                control = new FWDetailTableControl(RequestContext, For.Model as IEnumerable, For.Metadata);
                control.Attributes.Add("data-detailtype", "table");
                break;

            case FWDetailType.Grid:
                control = new FWDetailGridControl(RequestContext, For.Model as IEnumerable, For.Metadata);
                control.Attributes.Add("data-detailtype", "grid");
                break;
            }

            control.Attributes.Add("data-control", "detail");

            return(control);
        }
Пример #2
0
        /// <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>
        /// <param name="datasource">The checkbox datasource.</param>
        public FWCheckboxControl(FWRequestContext requestContext, object model, ModelMetadata metadata, IEnumerable <FWDatasourceItem> datasource)
            : base(requestContext, model, metadata)
        {
            _values = new Dictionary <string, string>();
            foreach (var item in datasource)
            {
                _values.Add(item.Id, item.Value);
            }

            if (FWReflectionHelper.IsCollection(metadata.ModelType))
            {
                var list = model as IEnumerable;
                foreach (var item in list)
                {
                    _selected.Add(item.ToString());
                }
            }
            else
            {
                if (model != null)
                {
                    _selected.Add(model.ToString());
                }
            }
        }
 /// <summary>
 /// Adds a property to the model.
 /// </summary>
 /// <param name="prop">The property PropertyInfo.</param>
 /// <param name="model">The model object reference.</param>
 private void Databind(PropertyInfo prop, object model)
 {
     if (FWReflectionHelper.IsPrimitive(prop.PropertyType))
     {
         BindPrimitive(prop, model);
     }
     else if (FWReflectionHelper.IsCollection(prop.PropertyType))
     {
         BindCollection(prop, model);
     }
 }
Пример #4
0
        /// <summary>
        /// Maps a source object to a target.
        /// </summary>
        /// <param name="source">The source object.</param>
        /// <param name="target">The target object.</param>
        protected sealed override void Inject(object source, object target)
        {
            if (source == null)
            {
                return;
            }

            var targetType = target.GetType();

            // Checks to see if its mapping a list
            if (FWReflectionHelper.IsCollection(targetType))
            {
                InjectCollection(source, target, targetType);
            }
            else
            {
                InjectMember(source, target, targetType);
            }
        }