Этап 3. Исправление и миграция

This commit is contained in:
prodigygirl 2023-04-05 18:55:35 +04:00
parent c23bffa073
commit 78ff9d797e
6 changed files with 1276 additions and 8 deletions

View File

@ -2,9 +2,9 @@
{
public interface IPatientModel : IId
{
string Surname { get; }
string? Surname { get; }
string Name { get; }
string Patronymic { get; }
string? Patronymic { get; }
DateTime BirthDate { get; }
int TreatmentId { get; }
}

View File

@ -9,7 +9,7 @@ namespace HospitalDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=FurnitureAssemblyDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=HospitalDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -0,0 +1,458 @@
// <auto-generated />
using System;
using HospitalDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace HospitalDatabaseImplement.Migrations
{
[DbContext(typeof(HospitalDatabase))]
[Migration("20230405144953_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("HospitalDatabaseImplement.Models.Apothecary", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(55)
.HasColumnType("nvarchar(55)");
b.HasKey("Id");
b.ToTable("Apothecaries");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApothecaryId")
.HasColumnType("int");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<string>("Dose")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("nvarchar(60)");
b.HasKey("Id");
b.HasIndex("ApothecaryId");
b.ToTable("Medicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDate")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.HasColumnType("nvarchar(max)");
b.Property<int>("TreatmentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TreatmentId");
b.ToTable("Patients");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Prescription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApothecaryId")
.HasColumnType("int");
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("Number")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ApothecaryId");
b.HasIndex("MedicineId");
b.ToTable("Prescriptions");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Procedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApothecaryId")
.HasColumnType("int");
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.HasIndex("ApothecaryId");
b.ToTable("Recipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("RecipeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("RecipeId");
b.ToTable("RecipeMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeTreatment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("RecipeId")
.HasColumnType("int");
b.Property<int>("TreatmentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RecipeId");
b.HasIndex("TreatmentId");
b.ToTable("RecipeTreatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Treatment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(55)
.HasColumnType("nvarchar(55)");
b.HasKey("Id");
b.ToTable("Treatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.TreatmentProcedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.Property<int>("TreatmentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProcedureId");
b.HasIndex("TreatmentId");
b.ToTable("TreatmentProcedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Apothecary", "Apothecary")
.WithMany()
.HasForeignKey("ApothecaryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Apothecary");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Treatment", "Treatment")
.WithMany("Patients")
.HasForeignKey("TreatmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Treatment");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Prescription", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Apothecary", "Apothecary")
.WithMany()
.HasForeignKey("ApothecaryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine")
.WithMany("Prescriptions")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Apothecary");
b.Navigation("Medicine");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine")
.WithMany("Procedures")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Medicines")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Procedure");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Apothecary", "Apothecary")
.WithMany()
.HasForeignKey("ApothecaryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Apothecary");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine")
.WithMany("Recipes")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Recipe", "Recipe")
.WithMany("Medicines")
.HasForeignKey("RecipeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Recipe");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeTreatment", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Recipe", "Recipe")
.WithMany("Treatments")
.HasForeignKey("RecipeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Treatment", "Treatment")
.WithMany("Recipes")
.HasForeignKey("TreatmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Recipe");
b.Navigation("Treatment");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.TreatmentProcedure", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Treatments")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Treatment", "Treatment")
.WithMany("Procedures")
.HasForeignKey("TreatmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Procedure");
b.Navigation("Treatment");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.Navigation("Prescriptions");
b.Navigation("Procedures");
b.Navigation("Recipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
{
b.Navigation("Medicines");
b.Navigation("Treatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.Navigation("Medicines");
b.Navigation("Treatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Treatment", b =>
{
b.Navigation("Patients");
b.Navigation("Procedures");
b.Navigation("Recipes");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,355 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace HospitalDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Apothecaries",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Login = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Password = table.Column<string>(type: "nvarchar(55)", maxLength: 55, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Apothecaries", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Procedures",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Procedures", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Treatments",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(55)", maxLength: 55, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Treatments", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Medicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(60)", maxLength: 60, nullable: false),
Cost = table.Column<double>(type: "float", nullable: false),
Dose = table.Column<string>(type: "nvarchar(10)", maxLength: 10, nullable: false),
ApothecaryId = table.Column<int>(type: "int", nullable: false, defaultValue: -1)
},
constraints: table =>
{
table.PrimaryKey("PK_Medicines", x => x.Id);
table.ForeignKey(
name: "FK_Medicines_Apothecaries_ApothecaryId",
column: x => x.ApothecaryId,
principalTable: "Apothecaries",
principalColumn: "Id",
onDelete: ReferentialAction.SetDefault);
});
migrationBuilder.CreateTable(
name: "Recipes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
ApothecaryId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Recipes", x => x.Id);
table.ForeignKey(
name: "FK_Recipes_Apothecaries_ApothecaryId",
column: x => x.ApothecaryId,
principalTable: "Apothecaries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Patients",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Surname = table.Column<string>(type: "nvarchar(max)", nullable: true),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Patronymic = table.Column<string>(type: "nvarchar(max)", nullable: true),
BirthDate = table.Column<DateTime>(type: "datetime2", nullable: false),
TreatmentId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Patients", x => x.Id);
table.ForeignKey(
name: "FK_Patients_Treatments_TreatmentId",
column: x => x.TreatmentId,
principalTable: "Treatments",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TreatmentProcedures",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProcedureId = table.Column<int>(type: "int", nullable: false),
TreatmentId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TreatmentProcedures", x => x.Id);
table.ForeignKey(
name: "FK_TreatmentProcedures_Procedures_ProcedureId",
column: x => x.ProcedureId,
principalTable: "Procedures",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TreatmentProcedures_Treatments_TreatmentId",
column: x => x.TreatmentId,
principalTable: "Treatments",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Prescriptions",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
Number = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false),
ApothecaryId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Prescriptions", x => x.Id);
table.ForeignKey(
name: "FK_Prescriptions_Apothecaries_ApothecaryId",
column: x => x.ApothecaryId,
principalTable: "Apothecaries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Prescriptions_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProcedureMedicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProcedureId = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProcedureMedicines", x => x.Id);
table.ForeignKey(
name: "FK_ProcedureMedicines_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProcedureMedicines_Procedures_ProcedureId",
column: x => x.ProcedureId,
principalTable: "Procedures",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "RecipeMedicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RecipeId = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RecipeMedicines", x => x.Id);
table.ForeignKey(
name: "FK_RecipeMedicines_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RecipeMedicines_Recipes_RecipeId",
column: x => x.RecipeId,
principalTable: "Recipes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "RecipeTreatments",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RecipeId = table.Column<int>(type: "int", nullable: false),
TreatmentId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RecipeTreatments", x => x.Id);
table.ForeignKey(
name: "FK_RecipeTreatments_Recipes_RecipeId",
column: x => x.RecipeId,
principalTable: "Recipes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RecipeTreatments_Treatments_TreatmentId",
column: x => x.TreatmentId,
principalTable: "Treatments",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Medicines_ApothecaryId",
table: "Medicines",
column: "ApothecaryId");
migrationBuilder.CreateIndex(
name: "IX_Patients_TreatmentId",
table: "Patients",
column: "TreatmentId");
migrationBuilder.CreateIndex(
name: "IX_Prescriptions_ApothecaryId",
table: "Prescriptions",
column: "ApothecaryId");
migrationBuilder.CreateIndex(
name: "IX_Prescriptions_MedicineId",
table: "Prescriptions",
column: "MedicineId");
migrationBuilder.CreateIndex(
name: "IX_ProcedureMedicines_MedicineId",
table: "ProcedureMedicines",
column: "MedicineId");
migrationBuilder.CreateIndex(
name: "IX_ProcedureMedicines_ProcedureId",
table: "ProcedureMedicines",
column: "ProcedureId");
migrationBuilder.CreateIndex(
name: "IX_RecipeMedicines_MedicineId",
table: "RecipeMedicines",
column: "MedicineId");
migrationBuilder.CreateIndex(
name: "IX_RecipeMedicines_RecipeId",
table: "RecipeMedicines",
column: "RecipeId");
migrationBuilder.CreateIndex(
name: "IX_Recipes_ApothecaryId",
table: "Recipes",
column: "ApothecaryId");
migrationBuilder.CreateIndex(
name: "IX_RecipeTreatments_RecipeId",
table: "RecipeTreatments",
column: "RecipeId");
migrationBuilder.CreateIndex(
name: "IX_RecipeTreatments_TreatmentId",
table: "RecipeTreatments",
column: "TreatmentId");
migrationBuilder.CreateIndex(
name: "IX_TreatmentProcedures_ProcedureId",
table: "TreatmentProcedures",
column: "ProcedureId");
migrationBuilder.CreateIndex(
name: "IX_TreatmentProcedures_TreatmentId",
table: "TreatmentProcedures",
column: "TreatmentId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Patients");
migrationBuilder.DropTable(
name: "Prescriptions");
migrationBuilder.DropTable(
name: "ProcedureMedicines");
migrationBuilder.DropTable(
name: "RecipeMedicines");
migrationBuilder.DropTable(
name: "RecipeTreatments");
migrationBuilder.DropTable(
name: "TreatmentProcedures");
migrationBuilder.DropTable(
name: "Medicines");
migrationBuilder.DropTable(
name: "Recipes");
migrationBuilder.DropTable(
name: "Procedures");
migrationBuilder.DropTable(
name: "Treatments");
migrationBuilder.DropTable(
name: "Apothecaries");
}
}
}

View File

@ -0,0 +1,455 @@
// <auto-generated />
using System;
using HospitalDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace HospitalDatabaseImplement.Migrations
{
[DbContext(typeof(HospitalDatabase))]
partial class HospitalDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("HospitalDatabaseImplement.Models.Apothecary", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(55)
.HasColumnType("nvarchar(55)");
b.HasKey("Id");
b.ToTable("Apothecaries");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApothecaryId")
.HasColumnType("int");
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<string>("Dose")
.IsRequired()
.HasMaxLength(10)
.HasColumnType("nvarchar(10)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(60)
.HasColumnType("nvarchar(60)");
b.HasKey("Id");
b.HasIndex("ApothecaryId");
b.ToTable("Medicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("BirthDate")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Patronymic")
.HasColumnType("nvarchar(max)");
b.Property<string>("Surname")
.HasColumnType("nvarchar(max)");
b.Property<int>("TreatmentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TreatmentId");
b.ToTable("Patients");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Prescription", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApothecaryId")
.HasColumnType("int");
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("Number")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ApothecaryId");
b.HasIndex("MedicineId");
b.ToTable("Prescriptions");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Procedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ApothecaryId")
.HasColumnType("int");
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.HasIndex("ApothecaryId");
b.ToTable("Recipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("RecipeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("RecipeId");
b.ToTable("RecipeMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeTreatment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("RecipeId")
.HasColumnType("int");
b.Property<int>("TreatmentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RecipeId");
b.HasIndex("TreatmentId");
b.ToTable("RecipeTreatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Treatment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(55)
.HasColumnType("nvarchar(55)");
b.HasKey("Id");
b.ToTable("Treatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.TreatmentProcedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.Property<int>("TreatmentId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ProcedureId");
b.HasIndex("TreatmentId");
b.ToTable("TreatmentProcedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Apothecary", "Apothecary")
.WithMany()
.HasForeignKey("ApothecaryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Apothecary");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Treatment", "Treatment")
.WithMany("Patients")
.HasForeignKey("TreatmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Treatment");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Prescription", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Apothecary", "Apothecary")
.WithMany()
.HasForeignKey("ApothecaryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine")
.WithMany("Prescriptions")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Apothecary");
b.Navigation("Medicine");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine")
.WithMany("Procedures")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Medicines")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Procedure");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Apothecary", "Apothecary")
.WithMany()
.HasForeignKey("ApothecaryId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Apothecary");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine")
.WithMany("Recipes")
.HasForeignKey("MedicineId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Recipe", "Recipe")
.WithMany("Medicines")
.HasForeignKey("RecipeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Medicine");
b.Navigation("Recipe");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeTreatment", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Recipe", "Recipe")
.WithMany("Treatments")
.HasForeignKey("RecipeId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Treatment", "Treatment")
.WithMany("Recipes")
.HasForeignKey("TreatmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Recipe");
b.Navigation("Treatment");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.TreatmentProcedure", b =>
{
b.HasOne("HospitalDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Treatments")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("HospitalDatabaseImplement.Models.Treatment", "Treatment")
.WithMany("Procedures")
.HasForeignKey("TreatmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Procedure");
b.Navigation("Treatment");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.Navigation("Prescriptions");
b.Navigation("Procedures");
b.Navigation("Recipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
{
b.Navigation("Medicines");
b.Navigation("Treatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.Navigation("Medicines");
b.Navigation("Treatments");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Treatment", b =>
{
b.Navigation("Patients");
b.Navigation("Procedures");
b.Navigation("Recipes");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -14,16 +14,16 @@ namespace HospitalDatabaseImplement.Models
{
public int Id { get; private set; }
public string Surname { get; private set; } = string.Empty;
public string? Surname { get; private set; } = string.Empty;
[Required]
public string Name { get; private set; } = string.Empty;
public string Patronymic { get; private set; } = string.Empty;
public string? Patronymic { get; private set; } = string.Empty;
[Required]
public DateTime BirthDate { get; private set; }
public int TreatmentId { get; private set; }
public virtual Treatment? Treatment { get; set; }
public virtual Treatment Treatment { get; set; }
public static Patient? Create(PatientBindingModel model)
{
@ -76,7 +76,7 @@ namespace HospitalDatabaseImplement.Models
Patronymic = Patronymic,
BirthDate = BirthDate,
TreatmentId = TreatmentId,
TreatmentName = Treatment?.Name
TreatmentName = Treatment.Name
};
}
}