diff --git a/Hospital/HospitalDataModels/Models/IPatientModel.cs b/Hospital/HospitalDataModels/Models/IPatientModel.cs
index c28fefa..c8aa3c0 100644
--- a/Hospital/HospitalDataModels/Models/IPatientModel.cs
+++ b/Hospital/HospitalDataModels/Models/IPatientModel.cs
@@ -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; }
}
diff --git a/Hospital/HospitalDatabaseImplement/HospitalDatabase.cs b/Hospital/HospitalDatabaseImplement/HospitalDatabase.cs
index 92ddb35..8822435 100644
--- a/Hospital/HospitalDatabaseImplement/HospitalDatabase.cs
+++ b/Hospital/HospitalDatabaseImplement/HospitalDatabase.cs
@@ -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);
}
diff --git a/Hospital/HospitalDatabaseImplement/Migrations/20230405144953_InitialCreate.Designer.cs b/Hospital/HospitalDatabaseImplement/Migrations/20230405144953_InitialCreate.Designer.cs
new file mode 100644
index 0000000..ef464e0
--- /dev/null
+++ b/Hospital/HospitalDatabaseImplement/Migrations/20230405144953_InitialCreate.Designer.cs
@@ -0,0 +1,458 @@
+//
+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
+ {
+ ///
+ 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("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Login")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("nvarchar(50)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasMaxLength(55)
+ .HasColumnType("nvarchar(55)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Apothecaries");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ApothecaryId")
+ .HasColumnType("int");
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.Property("Dose")
+ .IsRequired()
+ .HasMaxLength(10)
+ .HasColumnType("nvarchar(10)");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(60)
+ .HasColumnType("nvarchar(60)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ApothecaryId");
+
+ b.ToTable("Medicines");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("BirthDate")
+ .HasColumnType("datetime2");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Patronymic")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Surname")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("TreatmentId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TreatmentId");
+
+ b.ToTable("Patients");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Prescription", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ApothecaryId")
+ .HasColumnType("int");
+
+ b.Property("Date")
+ .HasColumnType("datetime2");
+
+ b.Property("MedicineId")
+ .HasColumnType("int");
+
+ b.Property("Number")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ApothecaryId");
+
+ b.HasIndex("MedicineId");
+
+ b.ToTable("Prescriptions");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("nvarchar(50)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Procedures");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("MedicineId")
+ .HasColumnType("int");
+
+ b.Property("ProcedureId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("MedicineId");
+
+ b.HasIndex("ProcedureId");
+
+ b.ToTable("ProcedureMedicines");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ApothecaryId")
+ .HasColumnType("int");
+
+ b.Property("Date")
+ .HasColumnType("datetime2");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("nvarchar(50)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ApothecaryId");
+
+ b.ToTable("Recipes");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("MedicineId")
+ .HasColumnType("int");
+
+ b.Property("RecipeId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("MedicineId");
+
+ b.HasIndex("RecipeId");
+
+ b.ToTable("RecipeMedicines");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeTreatment", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("RecipeId")
+ .HasColumnType("int");
+
+ b.Property("TreatmentId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RecipeId");
+
+ b.HasIndex("TreatmentId");
+
+ b.ToTable("RecipeTreatments");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Treatment", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(55)
+ .HasColumnType("nvarchar(55)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Treatments");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.TreatmentProcedure", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ProcedureId")
+ .HasColumnType("int");
+
+ b.Property("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
+ }
+ }
+}
diff --git a/Hospital/HospitalDatabaseImplement/Migrations/20230405144953_InitialCreate.cs b/Hospital/HospitalDatabaseImplement/Migrations/20230405144953_InitialCreate.cs
new file mode 100644
index 0000000..bf85384
--- /dev/null
+++ b/Hospital/HospitalDatabaseImplement/Migrations/20230405144953_InitialCreate.cs
@@ -0,0 +1,355 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace HospitalDatabaseImplement.Migrations
+{
+ ///
+ public partial class InitialCreate : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Apothecaries",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Login = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false),
+ Password = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Name = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Name = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Name = table.Column(type: "nvarchar(60)", maxLength: 60, nullable: false),
+ Cost = table.Column(type: "float", nullable: false),
+ Dose = table.Column(type: "nvarchar(10)", maxLength: 10, nullable: false),
+ ApothecaryId = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false),
+ Date = table.Column(type: "datetime2", nullable: false),
+ ApothecaryId = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Surname = table.Column(type: "nvarchar(max)", nullable: true),
+ Name = table.Column(type: "nvarchar(max)", nullable: false),
+ Patronymic = table.Column(type: "nvarchar(max)", nullable: true),
+ BirthDate = table.Column(type: "datetime2", nullable: false),
+ TreatmentId = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ProcedureId = table.Column(type: "int", nullable: false),
+ TreatmentId = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ Date = table.Column(type: "datetime2", nullable: false),
+ Number = table.Column(type: "int", nullable: false),
+ MedicineId = table.Column(type: "int", nullable: false),
+ ApothecaryId = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ProcedureId = table.Column(type: "int", nullable: false),
+ MedicineId = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ RecipeId = table.Column(type: "int", nullable: false),
+ MedicineId = table.Column(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(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ RecipeId = table.Column(type: "int", nullable: false),
+ TreatmentId = table.Column(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");
+ }
+
+ ///
+ 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");
+ }
+ }
+}
diff --git a/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs
new file mode 100644
index 0000000..913ba06
--- /dev/null
+++ b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs
@@ -0,0 +1,455 @@
+//
+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("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Login")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("nvarchar(50)");
+
+ b.Property("Password")
+ .IsRequired()
+ .HasMaxLength(55)
+ .HasColumnType("nvarchar(55)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Apothecaries");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ApothecaryId")
+ .HasColumnType("int");
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.Property("Dose")
+ .IsRequired()
+ .HasMaxLength(10)
+ .HasColumnType("nvarchar(10)");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(60)
+ .HasColumnType("nvarchar(60)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ApothecaryId");
+
+ b.ToTable("Medicines");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("BirthDate")
+ .HasColumnType("datetime2");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Patronymic")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Surname")
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("TreatmentId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TreatmentId");
+
+ b.ToTable("Patients");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Prescription", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ApothecaryId")
+ .HasColumnType("int");
+
+ b.Property("Date")
+ .HasColumnType("datetime2");
+
+ b.Property("MedicineId")
+ .HasColumnType("int");
+
+ b.Property("Number")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ApothecaryId");
+
+ b.HasIndex("MedicineId");
+
+ b.ToTable("Prescriptions");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("nvarchar(50)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Procedures");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("MedicineId")
+ .HasColumnType("int");
+
+ b.Property("ProcedureId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("MedicineId");
+
+ b.HasIndex("ProcedureId");
+
+ b.ToTable("ProcedureMedicines");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ApothecaryId")
+ .HasColumnType("int");
+
+ b.Property("Date")
+ .HasColumnType("datetime2");
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("nvarchar(50)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ApothecaryId");
+
+ b.ToTable("Recipes");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("MedicineId")
+ .HasColumnType("int");
+
+ b.Property("RecipeId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("MedicineId");
+
+ b.HasIndex("RecipeId");
+
+ b.ToTable("RecipeMedicines");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeTreatment", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("RecipeId")
+ .HasColumnType("int");
+
+ b.Property("TreatmentId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RecipeId");
+
+ b.HasIndex("TreatmentId");
+
+ b.ToTable("RecipeTreatments");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.Treatment", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasMaxLength(55)
+ .HasColumnType("nvarchar(55)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Treatments");
+ });
+
+ modelBuilder.Entity("HospitalDatabaseImplement.Models.TreatmentProcedure", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ProcedureId")
+ .HasColumnType("int");
+
+ b.Property("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
+ }
+ }
+}
diff --git a/Hospital/HospitalDatabaseImplement/Models/Patient.cs b/Hospital/HospitalDatabaseImplement/Models/Patient.cs
index a1fef36..43eef9d 100644
--- a/Hospital/HospitalDatabaseImplement/Models/Patient.cs
+++ b/Hospital/HospitalDatabaseImplement/Models/Patient.cs
@@ -13,17 +13,17 @@ namespace HospitalDatabaseImplement.Models
public class Patient : IPatientModel
{
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
};
}
}