예제 #1
0
        private async Task <IFormElement> GetFormField(DatabaseColumn col, IDictionary <string, object> dictionary)
        {
            if (col.IsForeignKey)
            {
                return(await GetSelector(col));
            }

            if (_dbInspector.IsLob(col))
            {
                return(new Input
                {
                    Id = col.Name,
                    Name = col.Name,
                    InputType = "file",
                });
            }

            var value = dictionary?[col.Name]?.ToString();

            return(Input.ForString(col.Name, value));
        }
예제 #2
0
        private HtmlElement DbValueToElement(string table, IDictionary <string, object> obj, KeyValuePair <string, object> kvp)
        {
            var col = _dbInspector.GetColumn(table, kvp.Key);

            if (col == null)
            {
                // throw new ArgumentException(nameof(col), kvp.Key);
                // return new Span(kvp.Value?.ToString());
            }

            if (_dbInspector.IsFk(table, kvp.Key))
            {
                var trg = _dbInspector.GetFkTarget(table, kvp.Key);
                return(new A
                {
                    // Text = trg + "#" + kvp.Value,
                    rel = trg,
                    Href = _linkManager.LinkToItem(trg, kvp.Value),
                    Subs = new Span(kvp.Value?.ToString())
                    {
                        Itemscope = false,
                        Itemprop = kvp.Key
                                   // Itemtype = kvp.Key,
                    }.ToArray()
                });
            }

            if (_dbInspector.GetPkColumn(table).Name == kvp.Key)
            {
                return(new A
                {
                    // Text = kvp.Value.ToString(),
                    rel = "self",
                    Href = _linkManager.LinkToItem(table, kvp.Value),
                    Subs = WithItemProp(new Span(kvp.Value?.ToString()), kvp.Key).ToArray(),
                    Itemscope = false,
                });
            }

            if (_dbInspector.IsLob(table, kvp.Key))
            {
                return(new A
                {
                    Text = "Download " + kvp.Key,
                    Href = _linkManager.LinkToLob(table, _dbInspector.GetId(table, obj), kvp.Key),
                    Itemscope = true, Itemprop = kvp.Key,
                });
            }

            if (kvp.Value is HtmlElement e)
            {
                return(WithItemProp(e, kvp.Key));
            }

            if (kvp.Value is HtmlElement[] ea)
            {
                return(new Ul(ea.Select(x => new Li(WithItemProp(x, kvp.Key)))));
            }

            return(WithItemProp(new Span(kvp.Value?.ToString()), kvp.Key));
        }