コード例 #1
0
ファイル: ApiController.cs プロジェクト: narve/enrest-core
        private IHtmlElement GetLinksForItem(string table, IDictionary <string, object> o)
        {
            var allFks = _dbInspector.GetSchema().Tables
                         .SelectMany(t => t.ForeignKeys).ToList();

            var incomingFkLinks = allFks
                                  .Where(fk => fk.RefersToTable == table)
                                  .Select(fk => GetInFkLink(table, fk, o))
                                  .ToArray();

            var outgoingFkLinks = allFks
                                  .Where(c => c.TableName == table)
                                  .Select(fk => GetOutFkLink(table, fk, o))
                                  .ToArray();

            var id        = _dbInspector.GetId(table, o);
            var editLinks = new[]
            {
                new A(_linkManager.LinkToItem(table, id), _dbInspector.GetTitle(table, o), "self")
                {
                    Itemscope = true,
                },
                new A(_linkManager.LinkToEditForm(table, id), $"Form for editing '{table}'#{id}", "create form")
                {
                    Itemscope = true,
                },
                new A(_linkManager.LinkToDeleteForm(table, id), "Form for deleting " + _dbInspector.GetTitle(table, o), "delete")
                {
                    Itemscope = true,
                },
            };

            var actions = table == "users"
                ? new A("/forms/login?user="******"email"]).ToArray()
                : Array.Empty <IHtmlElement>();

            var links = editLinks.Concat(outgoingFkLinks).Concat(incomingFkLinks).Concat(actions)
                        .Select(l => new Li(l))
                        .Cast <IHtmlElement>()
                        .ToArray();

            return(new Ul
            {
                Itemprop = "_links",
                Subs = links,
            });
        }
コード例 #2
0
ファイル: FormCreator.cs プロジェクト: narve/enrest-core
        private async Task <ImmutableSortedDictionary <string, string> > GetSelectorRows(string otherTable)
        {
            var select = $"select * from {otherTable}";
            var conn   = await _connectionProvider.Get();

            var rows = await conn.QueryAsync(select);

            var items = rows.Cast <IDictionary <string, object> >().ToList()
                        .Select(x => KeyValuePair.Create(_dbInspector.GetId(otherTable, x), _dbInspector.GetTitle(otherTable, x)))
                        .ToImmutableSortedDictionary();

            return(items);
        }