예제 #1
0
        public MetadataItem GetMetadata([FromUri] FilterModel filter)
        {
            try
            {
                var metadata = new MetadataItem();

                var fields = new List<Field>()
                            {

                                new Field()
                                    {
                                        Name = "FirstName",
                                        Caption = "First Name",
                                        Datatype = typeof (string).Name,
                                        Order = 1
                                    },
                                new Field()
                                    {
                                        Name = "LastName",
                                        Caption = "Last Name",
                                        Datatype = typeof (string).Name,
                                        Order = 2
                                    },
                                    new Field()
                                {
                                    Name = "FullName",
                                    Caption = "Full Name",
                                    Datatype = typeof (string).Name,
                                    Editable = false,
                                    Order = 0
                                }
                            };

                metadata = new MetadataItem
                {
                    Name = ControllerName,
                    Key = "FirstName",
                    Fields = fields,
                    RowCount = DataSources.Persons.Count
                };
                return metadata;
            }
            catch (Exception)
            {
                return null;
            }
        }
예제 #2
0
        public MetadataItem GetMetadataItem(string id)
        {
            var type = Type.GetType(ModelsNamespace + "." + id);

            if (type == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            try
            {
                var properties = type.GetProperties();
                var dynamicFields = new List<Field>();
                foreach (var prop in properties)
                {
                    Field field;
                    var customAttribute = (FieldAttribute)prop.GetCustomAttribute(typeof(FieldAttribute));
                    if (customAttribute != null)
                    {
                        field = new Field
                        {
                            Name = prop.Name,
                            Caption = !string.IsNullOrEmpty(customAttribute.Caption) ?
                                customAttribute.Caption :
                                Humanize(prop.Name),
                            Editable = customAttribute.Editable,
                            Datatype = !string.IsNullOrEmpty(customAttribute.Datatype) ?
                                customAttribute.Datatype : prop.PropertyType.Name,
                            Order = customAttribute.Order,
                            ColumnVisible = customAttribute.ColumnVisible,
                            FieldVisible = customAttribute.FieldVisible
                        };
                    }
                    else
                    {
                        field = new Field
                        {
                            Name = prop.Name,
                            Datatype = prop.PropertyType.Name,
                            Caption = Humanize(prop.Name)
                        };
                    }
                    dynamicFields.Add(field);
                }

                //dynamicFields = dynamicFields.OrderBy(x => x.Order).ToList();

                var item = new MetadataItem
                    {
                        Name = id,
                        Key = dynamicFields.First().Name,
                        Fields = dynamicFields,
                        RowCount = GetTypeRowCount(type)
                    };

                return item;
            }
            catch (Exception)
            {
                throw new HttpResponseException(HttpStatusCode.InternalServerError);
            }
        }