[HttpPost("column")]
public IActionResult AddColumn(AddColumn model)
{
try
{
using IDbConnection db = new NpgsqlConnection("postgres");
var addColumn = @$"alter table ""{model.TableName}"" add column ""{model.ColumnName}"" text;"
.Replace("\n", " ").Replace("\t", " ").Replace("\r", " ").TrimEnd(',');
db.Execute(addColumn);
return Ok();
}
catch (Exception e)
{
return BadRequest(e.Message);
}
}
public IActionResult CreateForm([FromBody] CreateForm model)
{
try
{
using IDbConnection db = new NpgsqlConnection("postgres");
var createFormsTable = @$"create table if not exists ""forms"" (
form_name text,
table_name text,
columns text[]
);".Replace("\n", " ").Replace("\t", " ").Replace("\r", " ").TrimEnd(',');
db.Execute(createFormsTable);
foreach (var form in model.Forms)
{
var columnsBuilder = new StringBuilder();
foreach (var item in form.Columns)
{
columnsBuilder.Append(@$"'{item}',");
}
var columns = columnsBuilder.ToString().TrimEnd(',');
var insertForm = @$"insert into ""forms"" values ('{model.FormName}','{form.TableName}', array [{columns}]);";
db.Execute(insertForm);
}
return Ok();
}
public IActionResult CreateForm([FromBody] CreateForm model)
{
try
{
using IDbConnection db = new NpgsqlConnection("postgres");
var createFormsTable = @$"create table if not exists ""forms"" (
form_name text,
table_name text,
columns text[]
);".Replace("\n", " ").Replace("\t", " ").Replace("\r", " ").TrimEnd(',');
db.Execute(createFormsTable);
foreach (var form in model.Forms)
{
var columnsBuilder = new StringBuilder();
foreach (var item in form.Columns)
{
columnsBuilder.Append(@$"'{item}',");
}
var columns = columnsBuilder.ToString().TrimEnd(',');
var insertForm = @$"insert into ""forms"" values ('{model.FormName}','{form.TableName}', array [{columns}]);";
db.Execute(insertForm);
}
return Ok();
}
public IActionResult CreateForm([FromBody] CreateForm model)
{
try
{
using IDbConnection db = new NpgsqlConnection("postgres");
var createFormsTable = @$"create table if not exists ""forms"" (
form_name text,
table_name text,
columns text[]
);".Replace("\n", " ").Replace("\t", " ").Replace("\r", " ").TrimEnd(',');
db.Execute(createFormsTable);
foreach (var form in model.Forms)
{
var columnsBuilder = new StringBuilder();
foreach (var item in form.Columns)
{
columnsBuilder.Append(@$"'{item}',");
}
var columns = columnsBuilder.ToString().TrimEnd(',');
var insertForm = @$"insert into ""forms"" values ('{model.FormName}','{form.TableName}', array [{columns}]);";
db.Execute(insertForm);
}
return Ok();
}
addStudent() {
const newStudent: IStudent = {
//вот здесь должен быть universityId
firstName: this.firstName,
lastName: this.lastName,
};
<div *ngIf="univer.isOpenModal">
<button (click)="univer.isOpenModal = false">Закрыть модальное окно</button>
<h1>Ученики {{ univer.nameOfUniversity }}</h1>
<button (click)="addStudent()">Добавить ученика</button>
<input type="number" hidden [(ngModel)]="univer.id" />
<input type="text" [(ngModel)]="firstName" />
<input type="text" [(ngModel)]="lastName" />
<div *ngFor="let student of univer.students">
<div>{{ student.firstName }}</div>
<div>{{ student.lastName }}</div>
<button (click)="removeStudent(student.id!)">
Удалить этого ученика
</button>
</div>
</div>
export interface IStudent {
id?: number;
firstName: string;
lastName: string;
universityId?: number;
}