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, }); }
public async Task <IDictionary <string, object> > InsertRow(string table, List <KeyValuePair <string, object> > formValues) { CheckColumnNames(table, formValues); var conn = await _connectionProvider.Get(); var tableInfo = _dbInspector.GetSchema().FindTableByName(table); var parameters = ToDbParameters(formValues, tableInfo); var colNames = parameters.Keys.Where(x => Regex.IsMatch(x, "^[\\w]+$")).ToList(); var sql = new[] { $"INSERT INTO {table}", $"({colNames.JoinToString()})", $"VALUES ({colNames.Select(x => "@" + x).JoinToString()}) " + $"RETURNING {table}.*" }.JoinToString(" \r\n"); var ins = await conn.QuerySingleAsync(sql, parameters); return(ins); }
public async Task <IHtmlElement> GetCreateForm(string table) { var tableInfo = _dbInspector.GetSchema().FindTableByName(table); return(Pimp($"Create new '{table}'", new Form { ExAttributes = new Dictionary <string, string>() { { "enctype", "multipart/form-data" } }, rel = "Create", Action = _linkManager.LinkToCreateAction(table), Method = HttpMethod.Post, Clz = $"create {table}", Subs = (await GetInputFields(tableInfo)) .Concat(GetSubmit(tableInfo)) .ToArray() })); }