Изменение модели + создание новой схемы БД

This commit is contained in:
parent 8c3f21221b
commit 675da0a5d9
14 changed files with 192 additions and 260 deletions

View File

@ -1,25 +0,0 @@
using System.Collections.Generic;
using System.Linq;
namespace AsbCloudApp.Data.Manuals;
/// <summary>
/// Элемент каталога инструкций
/// </summary>
public class CatalogItemManualDto
{
/// <summary>
/// DTO категории
/// </summary>
public FileCategoryDto Category { get; set; } = null!;
/// <summary>
/// DTO инструкций хранящиеся без папки
/// </summary>
public IEnumerable<ManualDto> ManualsWithoutFolder { get; set; } = Enumerable.Empty<ManualDto>();
/// <summary>
/// DTO папок с инструкциями
/// </summary>
public IEnumerable<ManualFolderDto> Folders { get; set; } = Enumerable.Empty<ManualFolderDto>();
}

View File

@ -4,9 +4,9 @@ using System.Linq;
namespace AsbCloudApp.Data.Manuals; namespace AsbCloudApp.Data.Manuals;
/// <summary> /// <summary>
/// DTO папки для хранения инструкций /// Директория для хранения инструкций
/// </summary> /// </summary>
public class ManualFolderDto : IId public class ManualDirectoryDto : IId
{ {
/// <inheritdoc/> /// <inheritdoc/>
public int Id { get; set; } public int Id { get; set; }
@ -17,19 +17,14 @@ public class ManualFolderDto : IId
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
/// <summary> /// <summary>
/// Id родительской папки /// Id родительской директории
/// </summary> /// </summary>
public int? IdParent { get; set; } public int? IdParent { get; set; }
/// <summary> /// <summary>
/// Id категории /// Вложенные директории
/// </summary> /// </summary>
public int IdCategory { get; set; } public IEnumerable<ManualDirectoryDto> Children { get; set; } = Enumerable.Empty<ManualDirectoryDto>();
/// <summary>
/// Вложенные папки
/// </summary>
public IEnumerable<ManualFolderDto> Children { get; set; } = Enumerable.Empty<ManualFolderDto>();
/// <summary> /// <summary>
/// Хранимые инструкции /// Хранимые инструкции

View File

@ -3,7 +3,7 @@ using System;
namespace AsbCloudApp.Data.Manuals; namespace AsbCloudApp.Data.Manuals;
/// <summary> /// <summary>
/// DTO инструкции /// Инструкция
/// </summary> /// </summary>
public class ManualDto : IId public class ManualDto : IId
{ {
@ -21,12 +21,17 @@ public class ManualDto : IId
public DateTime DateDownload { get; set; } public DateTime DateDownload { get; set; }
/// <summary> /// <summary>
/// Id папки /// Id автора
/// </summary> /// </summary>
public int? IdFolder { get; set; } public int IdAuthor { get; set; }
/// <summary>
/// Id директории
/// </summary>
public int IdDirectory { get; set; }
/// <summary> /// <summary>
/// Id категории файла /// Id категории файла
/// </summary> /// </summary>
public int? IdCategory { get; set; } public int IdCategory { get; set; }
} }

View File

@ -13,7 +13,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace AsbCloudDb.Migrations namespace AsbCloudDb.Migrations
{ {
[DbContext(typeof(AsbCloudDbContext))] [DbContext(typeof(AsbCloudDbContext))]
[Migration("20230810052950_Add_Manuals")] [Migration("20230907070954_Add_Manuals")]
partial class Add_Manuals partial class Add_Manuals
{ {
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -21,7 +21,7 @@ namespace AsbCloudDb.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder modelBuilder
.UseCollation("Russian_Russia.1251") .UseCollation("Russian_Russia.1251")
.HasAnnotation("ProductVersion", "6.0.20") .HasAnnotation("ProductVersion", "6.0.21")
.HasAnnotation("Relational:MaxIdentifierLength", 63); .HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack"); NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
@ -434,11 +434,6 @@ namespace AsbCloudDb.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int?>("IdType")
.HasColumnType("integer")
.HasColumnName("type")
.HasComment("0 = Инструкции");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text") .HasColumnType("text")
@ -796,14 +791,7 @@ namespace AsbCloudDb.Migrations
new new
{ {
Id = 30000, Id = 30000,
IdType = 0, Name = "Инструкции"
Name = "АСУ ТП"
},
new
{
Id = 30001,
IdType = 0,
Name = "Технология бурения"
}); });
}); });
@ -1097,36 +1085,43 @@ namespace AsbCloudDb.Migrations
b.Property<DateTime>("DateDownload") b.Property<DateTime>("DateDownload")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("date_download") .HasColumnName("date_download")
.HasComment("Дата загрузки файла"); .HasComment("Дата загрузки");
b.Property<int?>("IdCategory") b.Property<int>("IdAuthor")
.HasColumnType("integer")
.HasColumnName("id_author")
.HasComment("Id автора");
b.Property<int>("IdCategory")
.HasColumnType("integer") .HasColumnType("integer")
.HasColumnName("id_category") .HasColumnName("id_category")
.HasComment("Категория"); .HasComment("Id категории файла");
b.Property<int?>("IdFolder") b.Property<int>("IdDirectory")
.HasColumnType("integer") .HasColumnType("integer")
.HasColumnName("id_folder") .HasColumnName("id_directory")
.HasComment("Id папки инструкций"); .HasComment("Id директории");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text") .HasColumnType("text")
.HasColumnName("name") .HasColumnName("name")
.HasComment("Название файла"); .HasComment("Название");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("IdAuthor");
b.HasIndex("IdCategory"); b.HasIndex("IdCategory");
b.HasIndex("IdFolder"); b.HasIndex("IdDirectory");
b.ToTable("t_manual"); b.ToTable("t_manual");
b.HasComment("Инструкции"); b.HasComment("Инструкции");
}); });
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b => modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualDirectory", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -1135,31 +1130,24 @@ namespace AsbCloudDb.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("IdCategory")
.HasColumnType("integer")
.HasColumnName("id_category")
.HasComment("Категория");
b.Property<int?>("IdParent") b.Property<int?>("IdParent")
.HasColumnType("integer") .HasColumnType("integer")
.HasColumnName("id_parent") .HasColumnName("id_parent")
.HasComment("Родительская папки"); .HasComment("Id родительской директории");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text") .HasColumnType("text")
.HasColumnName("name") .HasColumnName("name")
.HasComment("Название папки"); .HasComment("Название");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("IdCategory");
b.HasIndex("IdParent"); b.HasIndex("IdParent");
b.ToTable("t_manual_folder"); b.ToTable("t_manual_directory");
b.HasComment("Папка для инструкций"); b.HasComment("Директория для инструкций");
}); });
modelBuilder.Entity("AsbCloudDb.Model.Measure", b => modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
@ -2269,8 +2257,8 @@ namespace AsbCloudDb.Migrations
new new
{ {
Id = 524, Id = 524,
Description = "Разрешить просмотр инструкций", Description = "Разрешить получение инструкций",
Name = "Manual.view" Name = "Manual.get"
}); });
}); });
@ -7802,35 +7790,38 @@ namespace AsbCloudDb.Migrations
modelBuilder.Entity("AsbCloudDb.Model.Manuals.Manual", b => modelBuilder.Entity("AsbCloudDb.Model.Manuals.Manual", b =>
{ {
b.HasOne("AsbCloudDb.Model.FileCategory", "Category") b.HasOne("AsbCloudDb.Model.User", "Author")
.WithMany() .WithMany()
.HasForeignKey("IdCategory"); .HasForeignKey("IdAuthor")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.Manuals.ManualFolder", "Folder")
.WithMany("Manuals")
.HasForeignKey("IdFolder")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Category");
b.Navigation("Folder");
});
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b =>
{
b.HasOne("AsbCloudDb.Model.FileCategory", "Category") b.HasOne("AsbCloudDb.Model.FileCategory", "Category")
.WithMany() .WithMany()
.HasForeignKey("IdCategory") .HasForeignKey("IdCategory")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("AsbCloudDb.Model.Manuals.ManualFolder", "Parent") b.HasOne("AsbCloudDb.Model.Manuals.ManualDirectory", "Directory")
.WithMany("Manuals")
.HasForeignKey("IdDirectory")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
b.Navigation("Category");
b.Navigation("Directory");
});
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualDirectory", b =>
{
b.HasOne("AsbCloudDb.Model.Manuals.ManualDirectory", "Parent")
.WithMany("Children") .WithMany("Children")
.HasForeignKey("IdParent") .HasForeignKey("IdParent")
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
b.Navigation("Category");
b.Navigation("Parent"); b.Navigation("Parent");
}); });
@ -8459,7 +8450,7 @@ namespace AsbCloudDb.Migrations
b.Navigation("FileMarks"); b.Navigation("FileMarks");
}); });
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b => modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualDirectory", b =>
{ {
b.Navigation("Children"); b.Navigation("Children");

View File

@ -10,40 +10,26 @@ namespace AsbCloudDb.Migrations
{ {
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.AddColumn<int>(
name: "type",
table: "t_file_category",
type: "integer",
nullable: true,
comment: "0 = Инструкции");
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "t_manual_folder", name: "t_manual_directory",
columns: table => new columns: table => new
{ {
id = table.Column<int>(type: "integer", nullable: false) id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
name = table.Column<string>(type: "text", nullable: false, comment: "Название папки"), name = table.Column<string>(type: "text", nullable: false, comment: "Название"),
id_parent = table.Column<int>(type: "integer", nullable: true, comment: "Родительская папки"), id_parent = table.Column<int>(type: "integer", nullable: true, comment: "Id родительской директории")
id_category = table.Column<int>(type: "integer", nullable: false, comment: "Категория")
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_t_manual_folder", x => x.id); table.PrimaryKey("PK_t_manual_directory", x => x.id);
table.ForeignKey( table.ForeignKey(
name: "FK_t_manual_folder_t_file_category_id_category", name: "FK_t_manual_directory_t_manual_directory_id_parent",
column: x => x.id_category,
principalTable: "t_file_category",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_manual_folder_t_manual_folder_id_parent",
column: x => x.id_parent, column: x => x.id_parent,
principalTable: "t_manual_folder", principalTable: "t_manual_directory",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}, },
comment: "Папка для инструкций"); comment: "Директория для инструкций");
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "t_manual", name: "t_manual",
@ -51,10 +37,11 @@ namespace AsbCloudDb.Migrations
{ {
id = table.Column<int>(type: "integer", nullable: false) id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
name = table.Column<string>(type: "text", nullable: false, comment: "Название файла"), name = table.Column<string>(type: "text", nullable: false, comment: "Название"),
date_download = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "Дата загрузки файла"), date_download = table.Column<DateTime>(type: "timestamp with time zone", nullable: false, comment: "Дата загрузки"),
id_category = table.Column<int>(type: "integer", nullable: true, comment: "Категория"), id_directory = table.Column<int>(type: "integer", nullable: false, comment: "Id директории"),
id_folder = table.Column<int>(type: "integer", nullable: true, comment: "Id папки инструкций") id_category = table.Column<int>(type: "integer", nullable: false, comment: "Id категории файла"),
id_author = table.Column<int>(type: "integer", nullable: false, comment: "Id автора")
}, },
constraints: table => constraints: table =>
{ {
@ -63,11 +50,18 @@ namespace AsbCloudDb.Migrations
name: "FK_t_manual_t_file_category_id_category", name: "FK_t_manual_t_file_category_id_category",
column: x => x.id_category, column: x => x.id_category,
principalTable: "t_file_category", principalTable: "t_file_category",
principalColumn: "id"); principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_t_manual_t_manual_folder_id_folder", name: "FK_t_manual_t_manual_directory_id_directory",
column: x => x.id_folder, column: x => x.id_directory,
principalTable: "t_manual_folder", principalTable: "t_manual_directory",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_t_manual_t_user_id_author",
column: x => x.id_author,
principalTable: "t_user",
principalColumn: "id", principalColumn: "id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}, },
@ -75,12 +69,8 @@ namespace AsbCloudDb.Migrations
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "t_file_category", table: "t_file_category",
columns: new[] { "id", "type", "name", "short_name" }, columns: new[] { "id", "name", "short_name" },
values: new object[,] values: new object[] { 30000, "Инструкции", null });
{
{ 30000, 0, "АСУ ТП", null },
{ 30001, 0, "Технология бурения", null }
});
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "t_permission", table: "t_permission",
@ -88,7 +78,7 @@ namespace AsbCloudDb.Migrations
values: new object[,] values: new object[,]
{ {
{ 523, "Разрешить редактирование инструкций", "Manual.edit" }, { 523, "Разрешить редактирование инструкций", "Manual.edit" },
{ 524, "Разрешить просмотр инструкций", "Manual.view" } { 524, "Разрешить получение инструкций", "Manual.get" }
}); });
migrationBuilder.InsertData( migrationBuilder.InsertData(
@ -100,24 +90,24 @@ namespace AsbCloudDb.Migrations
{ 524, 1 } { 524, 1 }
}); });
migrationBuilder.CreateIndex(
name: "IX_t_manual_id_author",
table: "t_manual",
column: "id_author");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_t_manual_id_category", name: "IX_t_manual_id_category",
table: "t_manual", table: "t_manual",
column: "id_category"); column: "id_category");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_t_manual_id_folder", name: "IX_t_manual_id_directory",
table: "t_manual", table: "t_manual",
column: "id_folder"); column: "id_directory");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_t_manual_folder_id_category", name: "IX_t_manual_directory_id_parent",
table: "t_manual_folder", table: "t_manual_directory",
column: "id_category");
migrationBuilder.CreateIndex(
name: "IX_t_manual_folder_id_parent",
table: "t_manual_folder",
column: "id_parent"); column: "id_parent");
} }
@ -127,18 +117,13 @@ namespace AsbCloudDb.Migrations
name: "t_manual"); name: "t_manual");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "t_manual_folder"); name: "t_manual_directory");
migrationBuilder.DeleteData( migrationBuilder.DeleteData(
table: "t_file_category", table: "t_file_category",
keyColumn: "id", keyColumn: "id",
keyValue: 30000); keyValue: 30000);
migrationBuilder.DeleteData(
table: "t_file_category",
keyColumn: "id",
keyValue: 30001);
migrationBuilder.DeleteData( migrationBuilder.DeleteData(
table: "t_relation_user_role_permission", table: "t_relation_user_role_permission",
keyColumns: new[] { "id_permission", "id_user_role" }, keyColumns: new[] { "id_permission", "id_user_role" },
@ -158,10 +143,6 @@ namespace AsbCloudDb.Migrations
table: "t_permission", table: "t_permission",
keyColumn: "id", keyColumn: "id",
keyValue: 524); keyValue: 524);
migrationBuilder.DropColumn(
name: "type",
table: "t_file_category");
} }
} }
} }

View File

@ -432,11 +432,6 @@ namespace AsbCloudDb.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int?>("IdType")
.HasColumnType("integer")
.HasColumnName("type")
.HasComment("0 = Инструкции");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text") .HasColumnType("text")
@ -794,14 +789,7 @@ namespace AsbCloudDb.Migrations
new new
{ {
Id = 30000, Id = 30000,
IdType = 0, Name = "Инструкции"
Name = "АСУ ТП"
},
new
{
Id = 30001,
IdType = 0,
Name = "Технология бурения"
}); });
}); });
@ -1095,36 +1083,43 @@ namespace AsbCloudDb.Migrations
b.Property<DateTime>("DateDownload") b.Property<DateTime>("DateDownload")
.HasColumnType("timestamp with time zone") .HasColumnType("timestamp with time zone")
.HasColumnName("date_download") .HasColumnName("date_download")
.HasComment("Дата загрузки файла"); .HasComment("Дата загрузки");
b.Property<int?>("IdCategory") b.Property<int>("IdAuthor")
.HasColumnType("integer")
.HasColumnName("id_author")
.HasComment("Id автора");
b.Property<int>("IdCategory")
.HasColumnType("integer") .HasColumnType("integer")
.HasColumnName("id_category") .HasColumnName("id_category")
.HasComment("Категория"); .HasComment("Id категории файла");
b.Property<int?>("IdFolder") b.Property<int>("IdDirectory")
.HasColumnType("integer") .HasColumnType("integer")
.HasColumnName("id_folder") .HasColumnName("id_directory")
.HasComment("Id папки инструкций"); .HasComment("Id директории");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text") .HasColumnType("text")
.HasColumnName("name") .HasColumnName("name")
.HasComment("Название файла"); .HasComment("Название");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("IdAuthor");
b.HasIndex("IdCategory"); b.HasIndex("IdCategory");
b.HasIndex("IdFolder"); b.HasIndex("IdDirectory");
b.ToTable("t_manual"); b.ToTable("t_manual");
b.HasComment("Инструкции"); b.HasComment("Инструкции");
}); });
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b => modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualDirectory", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
@ -1133,31 +1128,24 @@ namespace AsbCloudDb.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("IdCategory")
.HasColumnType("integer")
.HasColumnName("id_category")
.HasComment("Категория");
b.Property<int?>("IdParent") b.Property<int?>("IdParent")
.HasColumnType("integer") .HasColumnType("integer")
.HasColumnName("id_parent") .HasColumnName("id_parent")
.HasComment("Родительская папки"); .HasComment("Id родительской директории");
b.Property<string>("Name") b.Property<string>("Name")
.IsRequired() .IsRequired()
.HasColumnType("text") .HasColumnType("text")
.HasColumnName("name") .HasColumnName("name")
.HasComment("Название папки"); .HasComment("Название");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("IdCategory");
b.HasIndex("IdParent"); b.HasIndex("IdParent");
b.ToTable("t_manual_folder"); b.ToTable("t_manual_directory");
b.HasComment("Папка для инструкций"); b.HasComment("Директория для инструкций");
}); });
modelBuilder.Entity("AsbCloudDb.Model.Measure", b => modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
@ -2267,8 +2255,8 @@ namespace AsbCloudDb.Migrations
new new
{ {
Id = 524, Id = 524,
Description = "Разрешить просмотр инструкций", Description = "Разрешить получение инструкций",
Name = "Manual.view" Name = "Manual.get"
}); });
}); });
@ -7800,35 +7788,38 @@ namespace AsbCloudDb.Migrations
modelBuilder.Entity("AsbCloudDb.Model.Manuals.Manual", b => modelBuilder.Entity("AsbCloudDb.Model.Manuals.Manual", b =>
{ {
b.HasOne("AsbCloudDb.Model.FileCategory", "Category") b.HasOne("AsbCloudDb.Model.User", "Author")
.WithMany() .WithMany()
.HasForeignKey("IdCategory"); .HasForeignKey("IdAuthor")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.Manuals.ManualFolder", "Folder")
.WithMany("Manuals")
.HasForeignKey("IdFolder")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Category");
b.Navigation("Folder");
});
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b =>
{
b.HasOne("AsbCloudDb.Model.FileCategory", "Category") b.HasOne("AsbCloudDb.Model.FileCategory", "Category")
.WithMany() .WithMany()
.HasForeignKey("IdCategory") .HasForeignKey("IdCategory")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("AsbCloudDb.Model.Manuals.ManualFolder", "Parent") b.HasOne("AsbCloudDb.Model.Manuals.ManualDirectory", "Directory")
.WithMany("Manuals")
.HasForeignKey("IdDirectory")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
b.Navigation("Category");
b.Navigation("Directory");
});
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualDirectory", b =>
{
b.HasOne("AsbCloudDb.Model.Manuals.ManualDirectory", "Parent")
.WithMany("Children") .WithMany("Children")
.HasForeignKey("IdParent") .HasForeignKey("IdParent")
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
b.Navigation("Category");
b.Navigation("Parent"); b.Navigation("Parent");
}); });
@ -8457,7 +8448,7 @@ namespace AsbCloudDb.Migrations
b.Navigation("FileMarks"); b.Navigation("FileMarks");
}); });
modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualFolder", b => modelBuilder.Entity("AsbCloudDb.Model.Manuals.ManualDirectory", b =>
{ {
b.Navigation("Children"); b.Navigation("Children");

View File

@ -79,7 +79,7 @@ namespace AsbCloudDb.Model
public DbSet<Notification> Notifications => Set<Notification>(); public DbSet<Notification> Notifications => Set<Notification>();
public DbSet<NotificationCategory> NotificationCategories => Set<NotificationCategory>(); public DbSet<NotificationCategory> NotificationCategories => Set<NotificationCategory>();
public DbSet<Manual> Manuals => Set<Manual>(); public DbSet<Manual> Manuals => Set<Manual>();
public DbSet<ManualFolder> ManualFolders => Set<ManualFolder>(); public DbSet<ManualDirectory> ManualDirectories => Set<ManualDirectory>();
public AsbCloudDbContext() : base() public AsbCloudDbContext() : base()
@ -392,16 +392,16 @@ namespace AsbCloudDb.Model
entity.HasKey(x => new { x.IdWell, x.IdUser }); entity.HasKey(x => new { x.IdWell, x.IdUser });
}); });
modelBuilder.Entity<ManualFolder>() modelBuilder.Entity<ManualDirectory>()
.HasOne(mf => mf.Parent) .HasOne(mf => mf.Parent)
.WithMany(mf => mf.Children) .WithMany(mf => mf.Children)
.HasForeignKey(mf => mf.IdParent) .HasForeignKey(mf => mf.IdParent)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Manual>() modelBuilder.Entity<Manual>()
.HasOne(m => m.Folder) .HasOne(m => m.Directory)
.WithMany(f => f.Manuals) .WithMany(f => f.Manuals)
.HasForeignKey(m => m.IdFolder) .HasForeignKey(m => m.IdDirectory)
.OnDelete(DeleteBehavior.Cascade); .OnDelete(DeleteBehavior.Cascade);
DefaultData.DefaultContextData.Fill(modelBuilder); DefaultData.DefaultContextData.Fill(modelBuilder);

View File

@ -75,8 +75,7 @@
new () {Id = 20000, Name = "Справки по страницам"}, new () {Id = 20000, Name = "Справки по страницам"},
new() { Id = 30000, Name = "АСУ ТП", IdType = FileCategory.IdFileCategoryTypeManuals}, new() { Id = 30000, Name = "Инструкции"},
new() { Id = 30001, Name = "Технология бурения", IdType = FileCategory.IdFileCategoryTypeManuals}
}; };
} }
} }

View File

@ -158,7 +158,7 @@
new() { Id = 522, Name = "UserSettings.delete", Description = "Разрешить удаление всех настроек пользователя"}, new() { Id = 522, Name = "UserSettings.delete", Description = "Разрешить удаление всех настроек пользователя"},
new() { Id = 523, Name = "Manual.edit", Description = "Разрешить редактирование инструкций" }, new() { Id = 523, Name = "Manual.edit", Description = "Разрешить редактирование инструкций" },
new() { Id = 524, Name = "Manual.view", Description = "Разрешить просмотр инструкций"} new() { Id = 524, Name = "Manual.get", Description = "Разрешить получение инструкций"}
}; };
} }
} }

View File

@ -7,8 +7,6 @@ namespace AsbCloudDb.Model
[Table("t_file_category"), Comment("Категории файлов")] [Table("t_file_category"), Comment("Категории файлов")]
public class FileCategory : IId public class FileCategory : IId
{ {
public const int IdFileCategoryTypeManuals = 0;
[Key] [Key]
[Column("id")] [Column("id")]
public int Id { get; set; } public int Id { get; set; }
@ -18,8 +16,5 @@ namespace AsbCloudDb.Model
[Column("short_name"), Comment("Короткое название категории")] [Column("short_name"), Comment("Короткое название категории")]
public string? ShortName { get; set; } public string? ShortName { get; set; }
[Column("type"), Comment("0 = Инструкции")]
public int? IdType { get; set; }
} }
} }

View File

@ -72,7 +72,7 @@ namespace AsbCloudDb.Model
DbSet<Notification> Notifications { get; } DbSet<Notification> Notifications { get; }
DbSet<NotificationCategory> NotificationCategories { get; } DbSet<NotificationCategory> NotificationCategories { get; }
DbSet<Manual> Manuals { get; } DbSet<Manual> Manuals { get; }
DbSet<ManualFolder> ManualFolders { get; } DbSet<ManualDirectory> ManualDirectories { get; }
DatabaseFacade Database { get; } DatabaseFacade Database { get; }
Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token); Task<int> RefreshMaterializedViewAsync(string mwName, CancellationToken token);

View File

@ -12,21 +12,27 @@ public class Manual : IId
[Column("id")] [Column("id")]
public int Id { get; set; } public int Id { get; set; }
[Column("name"), Comment("Название файла")] [Column("name"), Comment("Название")]
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
[Column("date_download"), Comment("Дата загрузки файла")] [Column("date_download"), Comment("Дата загрузки")]
public DateTime DateDownload { get; set; } public DateTime DateDownload { get; set; }
[Column("id_category"), Comment("Категория")] [Column("id_directory"), Comment("Id директории")]
public int? IdCategory { get; set; } public int IdDirectory { get; set; }
[Column("id_category"), Comment("Id категории файла")]
public int IdCategory { get; set; }
[Column("id_author"), Comment("Id автора")]
public int IdAuthor { get; set; }
[ForeignKey(nameof(IdDirectory))]
public virtual ManualDirectory Directory { get; set; } = null!;
[ForeignKey(nameof(IdCategory))] [ForeignKey(nameof(IdCategory))]
public virtual FileCategory? Category { get; set; } public virtual FileCategory Category { get; set; } = null!;
[Column("id_folder"), Comment("Id папки инструкций")] [ForeignKey(nameof(IdAuthor))]
public int? IdFolder { get; set; } public virtual User Author { get; set; } = null!;
[ForeignKey(nameof(IdFolder))]
public virtual ManualFolder? Folder { get; set; }
} }

View File

@ -0,0 +1,27 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudDb.Model.Manuals;
[Table("t_manual_directory"), Comment("Директория для инструкций")]
public class ManualDirectory : IId
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("name"), Comment("Название")]
public string Name { get; set; } = null!;
[Column("id_parent"), Comment("Id родительской директории")]
public int? IdParent { get; set; }
[ForeignKey(nameof(IdParent))]
public virtual ManualDirectory? Parent { get; set; }
public virtual ICollection<ManualDirectory>? Children { get; set; }
public virtual ICollection<Manual>? Manuals { get; set; }
}

View File

@ -1,33 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
namespace AsbCloudDb.Model.Manuals;
[Table("t_manual_folder"), Comment("Папка для инструкций")]
public class ManualFolder : IId
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("name"), Comment("Название папки")]
public string Name { get; set; } = null!;
[Column("id_parent"), Comment("Родительская папки")]
public int? IdParent { get; set; }
[ForeignKey(nameof(IdParent))]
public virtual ManualFolder? Parent { get; set; }
[Column("id_category"), Comment("Категория")]
public int IdCategory { get; set; }
[ForeignKey(nameof(IdCategory))]
public virtual FileCategory Category { get; set; } = null!;
public virtual ICollection<ManualFolder>? Children { get; set; }
public virtual ICollection<Manual>? Manuals { get; set; }
}