From 30ea05901a7a10a7d85dbcb4cda91a2f71bea7d2 Mon Sep 17 00:00:00 2001 From: ValAnn Date: Mon, 29 Apr 2024 20:45:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D0=B5=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Migrations/20240429112728_Hospital.cs | 173 ------- ...20240429120033_CreateMigration.Designer.cs | 450 ------------------ .../20240429163909_InitialCreate.Designer.cs} | 8 +- ...ion.cs => 20240429163909_InitialCreate.cs} | 211 +++++--- .../HospitalDatabaseModelSnapshot.cs | 4 +- .../Models/Medicine.cs | 56 ++- .../Models/Procedure.cs | 6 +- 7 files changed, 210 insertions(+), 698 deletions(-) delete mode 100644 Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.cs delete mode 100644 Hospital/HospitalDatabaseImplement/Migrations/20240429120033_CreateMigration.Designer.cs rename Hospital/{HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs => HospitalDatabaseImplement/Migrations/20240429163909_InitialCreate.Designer.cs} (99%) rename Hospital/HospitalDatabaseImplement/Migrations/{20240429120033_CreateMigration.cs => 20240429163909_InitialCreate.cs} (77%) diff --git a/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.cs b/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.cs deleted file mode 100644 index 666d719..0000000 --- a/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace HospitalDatabaseImplement.Migrations -{ - /// - public partial class Hospital : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Date", - table: "Procedures", - type: "datetime2", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); - - migrationBuilder.AddColumn( - name: "DescriptionProcedureId", - table: "Procedures", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "IDescriptionProcedureId", - table: "Procedures", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.AddColumn( - name: "PharmacistId", - table: "Procedures", - type: "int", - nullable: false, - defaultValue: 0); - - migrationBuilder.CreateTable( - name: "Pharmacists", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Login = table.Column(type: "nvarchar(25)", maxLength: 25, nullable: false), - FIO = table.Column(type: "nvarchar(55)", maxLength: 55, nullable: false), - PhoneNumber = table.Column(type: "nvarchar(11)", maxLength: 11, nullable: false), - Password = table.Column(type: "nvarchar(30)", maxLength: 30, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Pharmacists", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "DescriptionProcedures", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - PharmacistId = table.Column(type: "int", nullable: false), - Description = table.Column(type: "nvarchar(150)", maxLength: 150, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_DescriptionProcedures", x => x.Id); - table.ForeignKey( - name: "FK_DescriptionProcedures_Pharmacists_PharmacistId", - column: x => x.PharmacistId, - principalTable: "Pharmacists", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Procedures_IDescriptionProcedureId", - table: "Procedures", - column: "IDescriptionProcedureId"); - - migrationBuilder.CreateIndex( - name: "IX_Procedures_PharmacistId", - table: "Procedures", - column: "PharmacistId"); - - migrationBuilder.CreateIndex( - name: "IX_Medicines_PharmacistId", - table: "Medicines", - column: "PharmacistId"); - - migrationBuilder.CreateIndex( - name: "IX_DescriptionProcedures_PharmacistId", - table: "DescriptionProcedures", - column: "PharmacistId"); - - migrationBuilder.AddForeignKey( - name: "FK_Medicines_Pharmacists_PharmacistId", - table: "Medicines", - column: "PharmacistId", - principalTable: "Pharmacists", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Procedures_DescriptionProcedures_IDescriptionProcedureId", - table: "Procedures", - column: "IDescriptionProcedureId", - principalTable: "DescriptionProcedures", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Procedures_Pharmacists_PharmacistId", - table: "Procedures", - column: "PharmacistId", - principalTable: "Pharmacists", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Medicines_Pharmacists_PharmacistId", - table: "Medicines"); - - migrationBuilder.DropForeignKey( - name: "FK_Procedures_DescriptionProcedures_IDescriptionProcedureId", - table: "Procedures"); - - migrationBuilder.DropForeignKey( - name: "FK_Procedures_Pharmacists_PharmacistId", - table: "Procedures"); - - migrationBuilder.DropTable( - name: "DescriptionProcedures"); - - migrationBuilder.DropTable( - name: "Pharmacists"); - - migrationBuilder.DropIndex( - name: "IX_Procedures_IDescriptionProcedureId", - table: "Procedures"); - - migrationBuilder.DropIndex( - name: "IX_Procedures_PharmacistId", - table: "Procedures"); - - migrationBuilder.DropIndex( - name: "IX_Medicines_PharmacistId", - table: "Medicines"); - - migrationBuilder.DropColumn( - name: "Date", - table: "Procedures"); - - migrationBuilder.DropColumn( - name: "DescriptionProcedureId", - table: "Procedures"); - - migrationBuilder.DropColumn( - name: "IDescriptionProcedureId", - table: "Procedures"); - - migrationBuilder.DropColumn( - name: "PharmacistId", - table: "Procedures"); - } - } -} diff --git a/Hospital/HospitalDatabaseImplement/Migrations/20240429120033_CreateMigration.Designer.cs b/Hospital/HospitalDatabaseImplement/Migrations/20240429120033_CreateMigration.Designer.cs deleted file mode 100644 index 1a61b6e..0000000 --- a/Hospital/HospitalDatabaseImplement/Migrations/20240429120033_CreateMigration.Designer.cs +++ /dev/null @@ -1,450 +0,0 @@ -// -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("20240429120033_CreateMigration")] - partial class CreateMigration - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.17") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasMaxLength(150) - .HasColumnType("nvarchar(150)"); - - b.Property("DoctorId") - .HasColumnType("int"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.ToTable("Diseases"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Doctor", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("FIO") - .IsRequired() - .HasMaxLength(30) - .HasColumnType("nvarchar(30)"); - - b.Property("Login") - .IsRequired() - .HasMaxLength(25) - .HasColumnType("nvarchar(25)"); - - b.Property("MailAddress") - .IsRequired() - .HasMaxLength(30) - .HasColumnType("nvarchar(30)"); - - b.Property("Password") - .IsRequired() - .HasMaxLength(30) - .HasColumnType("nvarchar(30)"); - - b.Property("PhoneNumber") - .IsRequired() - .HasMaxLength(11) - .HasColumnType("nvarchar(11)"); - - b.HasKey("Id"); - - b.ToTable("Doctors"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Address") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("BirthDate") - .HasColumnType("datetime2"); - - b.Property("DoctorId") - .HasColumnType("int"); - - b.Property("FIO") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.HasKey("Id"); - - b.HasIndex("DoctorId"); - - b.ToTable("Patients"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientProcedure", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PatientId") - .HasColumnType("int"); - - b.Property("ProcedureId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PatientId"); - - b.HasIndex("ProcedureId"); - - b.ToTable("PatientProcedures"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientRecipe", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("PatientId") - .HasColumnType("int"); - - b.Property("RecipeId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("PatientId"); - - b.HasIndex("RecipeId"); - - b.ToTable("PatientRecipes"); - }); - - 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.Modelss.Medicine", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("CountryOrigin") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("nvarchar(50)"); - - b.Property("PharmacistId") - .HasColumnType("int"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Medicines"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.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.Modelss.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.Modelss.Recipe", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("Description") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("DiseaseId") - .HasColumnType("int"); - - b.Property("DoctorId") - .HasColumnType("int"); - - b.Property("IssueDate") - .HasColumnType("datetime2"); - - b.HasKey("Id"); - - b.HasIndex("DiseaseId"); - - b.HasIndex("DoctorId"); - - b.ToTable("Recipes"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => - { - b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") - .WithMany("Diseases") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Doctor"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => - { - b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") - .WithMany("Patients") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Doctor"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientProcedure", b => - { - b.HasOne("HospitalDatabaseImplement.Models.Patient", "Patient") - .WithMany("Procedures") - .HasForeignKey("PatientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HospitalDatabaseImplement.Modelss.Procedure", "Procedure") - .WithMany("PatientProcedures") - .HasForeignKey("ProcedureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Patient"); - - b.Navigation("Procedure"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientRecipe", b => - { - b.HasOne("HospitalDatabaseImplement.Models.Patient", "Patient") - .WithMany("Recipes") - .HasForeignKey("PatientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HospitalDatabaseImplement.Modelss.Recipe", "Recipe") - .WithMany() - .HasForeignKey("RecipeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Patient"); - - b.Navigation("Recipe"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b => - { - b.HasOne("HospitalDatabaseImplement.Modelss.Medicine", "Medicine") - .WithMany("RecipeMedicines") - .HasForeignKey("MedicineId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HospitalDatabaseImplement.Modelss.Recipe", "Recipe") - .WithMany("Medicines") - .HasForeignKey("RecipeId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Medicine"); - - b.Navigation("Recipe"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.ProcedureMedicine", b => - { - b.HasOne("HospitalDatabaseImplement.Modelss.Medicine", "Medicine") - .WithMany() - .HasForeignKey("MedicineId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HospitalDatabaseImplement.Modelss.Procedure", "Procedure") - .WithMany("Medicines") - .HasForeignKey("ProcedureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Medicine"); - - b.Navigation("Procedure"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.Recipe", b => - { - b.HasOne("HospitalDatabaseImplement.Models.Disease", "Disease") - .WithMany("Recipes") - .HasForeignKey("DiseaseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") - .WithMany("Recipes") - .HasForeignKey("DoctorId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Disease"); - - b.Navigation("Doctor"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => - { - b.Navigation("Recipes"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Doctor", b => - { - b.Navigation("Diseases"); - - b.Navigation("Patients"); - - b.Navigation("Recipes"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => - { - b.Navigation("Procedures"); - - b.Navigation("Recipes"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.Medicine", b => - { - b.Navigation("RecipeMedicines"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.Procedure", b => - { - b.Navigation("Medicines"); - - b.Navigation("PatientProcedures"); - }); - - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.Recipe", b => - { - b.Navigation("Medicines"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs b/Hospital/HospitalDatabaseImplement/Migrations/20240429163909_InitialCreate.Designer.cs similarity index 99% rename from Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs rename to Hospital/HospitalDatabaseImplement/Migrations/20240429163909_InitialCreate.Designer.cs index 32b6305..5e137eb 100644 --- a/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs +++ b/Hospital/HospitalDatabaseImplement/Migrations/20240429163909_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace HospitalDatabaseImplement.Migrations { [DbContext(typeof(HospitalDatabase))] - [Migration("20240429112728_Hospital")] - partial class Hospital + [Migration("20240429163909_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -388,11 +388,13 @@ namespace HospitalDatabaseImplement.Migrations modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b => { - b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", null) + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", "Pharmacist") .WithMany("Medicines") .HasForeignKey("PharmacistId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Pharmacist"); }); modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => diff --git a/Hospital/HospitalDatabaseImplement/Migrations/20240429120033_CreateMigration.cs b/Hospital/HospitalDatabaseImplement/Migrations/20240429163909_InitialCreate.cs similarity index 77% rename from Hospital/HospitalDatabaseImplement/Migrations/20240429120033_CreateMigration.cs rename to Hospital/HospitalDatabaseImplement/Migrations/20240429163909_InitialCreate.cs index 0a972e4..1b57268 100644 --- a/Hospital/HospitalDatabaseImplement/Migrations/20240429120033_CreateMigration.cs +++ b/Hospital/HospitalDatabaseImplement/Migrations/20240429163909_InitialCreate.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace HospitalDatabaseImplement.Migrations { /// - public partial class CreateMigration : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -29,32 +29,19 @@ namespace HospitalDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "Medicines", + name: "Pharmacists", 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), - CountryOrigin = table.Column(type: "nvarchar(max)", nullable: false), - Price = table.Column(type: "float", nullable: false), - PharmacistId = table.Column(type: "int", nullable: false) + Login = table.Column(type: "nvarchar(25)", maxLength: 25, nullable: false), + FIO = table.Column(type: "nvarchar(55)", maxLength: 55, nullable: false), + PhoneNumber = table.Column(type: "nvarchar(11)", maxLength: 11, nullable: false), + Password = table.Column(type: "nvarchar(30)", maxLength: 30, nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Medicines", 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); + table.PrimaryKey("PK_Pharmacists", x => x.Id); }); migrationBuilder.CreateTable( @@ -101,27 +88,43 @@ namespace HospitalDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "ProcedureMedicines", + name: "DescriptionProcedures", 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) + PharmacistId = table.Column(type: "int", nullable: false), + Description = table.Column(type: "nvarchar(150)", maxLength: 150, nullable: false) }, constraints: table => { - table.PrimaryKey("PK_ProcedureMedicines", x => x.Id); + table.PrimaryKey("PK_DescriptionProcedures", x => x.Id); table.ForeignKey( - name: "FK_ProcedureMedicines_Medicines_MedicineId", - column: x => x.MedicineId, - principalTable: "Medicines", + name: "FK_DescriptionProcedures_Pharmacists_PharmacistId", + column: x => x.PharmacistId, + principalTable: "Pharmacists", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Medicines", + 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), + CountryOrigin = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false), + PharmacistId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Medicines", x => x.Id); table.ForeignKey( - name: "FK_ProcedureMedicines_Procedures_ProcedureId", - column: x => x.ProcedureId, - principalTable: "Procedures", + name: "FK_Medicines_Pharmacists_PharmacistId", + column: x => x.PharmacistId, + principalTable: "Pharmacists", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); @@ -150,6 +153,85 @@ namespace HospitalDatabaseImplement.Migrations name: "FK_Recipes_Doctors_DoctorId", column: x => x.DoctorId, principalTable: "Doctors", + principalColumn: "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), + Date = table.Column(type: "datetime2", nullable: false), + DescriptionProcedureId = table.Column(type: "int", nullable: false), + IDescriptionProcedureId = table.Column(type: "int", nullable: false), + PharmacistId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Procedures", x => x.Id); + table.ForeignKey( + name: "FK_Procedures_DescriptionProcedures_IDescriptionProcedureId", + column: x => x.IDescriptionProcedureId, + principalTable: "DescriptionProcedures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Procedures_Pharmacists_PharmacistId", + column: x => x.PharmacistId, + principalTable: "Pharmacists", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "PatientRecipes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PatientId = table.Column(type: "int", nullable: false), + RecipeId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PatientRecipes", x => x.Id); + table.ForeignKey( + name: "FK_PatientRecipes_Patients_PatientId", + column: x => x.PatientId, + principalTable: "Patients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PatientRecipes_Recipes_RecipeId", + column: x => x.RecipeId, + principalTable: "Recipes", + principalColumn: "Id"); + }); + + 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); }); @@ -181,62 +263,45 @@ namespace HospitalDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "PatientRecipes", + name: "ProcedureMedicines", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), - PatientId = table.Column(type: "int", nullable: false), - RecipeId = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PatientRecipes", x => x.Id); - table.ForeignKey( - name: "FK_PatientRecipes_Patients_PatientId", - column: x => x.PatientId, - principalTable: "Patients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_PatientRecipes_Recipes_RecipeId", - column: x => x.RecipeId, - principalTable: "Recipes", - 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), + ProcedureId = table.Column(type: "int", nullable: false), MedicineId = table.Column(type: "int", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_RecipeMedicines", x => x.Id); + table.PrimaryKey("PK_ProcedureMedicines", x => x.Id); table.ForeignKey( - name: "FK_RecipeMedicines_Medicines_MedicineId", + name: "FK_ProcedureMedicines_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); + name: "FK_ProcedureMedicines_Procedures_ProcedureId", + column: x => x.ProcedureId, + principalTable: "Procedures", + principalColumn: "Id"); }); + migrationBuilder.CreateIndex( + name: "IX_DescriptionProcedures_PharmacistId", + table: "DescriptionProcedures", + column: "PharmacistId"); + migrationBuilder.CreateIndex( name: "IX_Diseases_DoctorId", table: "Diseases", column: "DoctorId"); + migrationBuilder.CreateIndex( + name: "IX_Medicines_PharmacistId", + table: "Medicines", + column: "PharmacistId"); + migrationBuilder.CreateIndex( name: "IX_PatientProcedures_PatientId", table: "PatientProcedures", @@ -272,6 +337,16 @@ namespace HospitalDatabaseImplement.Migrations table: "ProcedureMedicines", column: "ProcedureId"); + migrationBuilder.CreateIndex( + name: "IX_Procedures_IDescriptionProcedureId", + table: "Procedures", + column: "IDescriptionProcedureId"); + + migrationBuilder.CreateIndex( + name: "IX_Procedures_PharmacistId", + table: "Procedures", + column: "PharmacistId"); + migrationBuilder.CreateIndex( name: "IX_RecipeMedicines_MedicineId", table: "RecipeMedicines", @@ -320,9 +395,15 @@ namespace HospitalDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Recipes"); + migrationBuilder.DropTable( + name: "DescriptionProcedures"); + migrationBuilder.DropTable( name: "Diseases"); + migrationBuilder.DropTable( + name: "Pharmacists"); + migrationBuilder.DropTable( name: "Doctors"); } diff --git a/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs index c0c0254..551a34c 100644 --- a/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs +++ b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs @@ -385,11 +385,13 @@ namespace HospitalDatabaseImplement.Migrations modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b => { - b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", null) + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", "Pharmacist") .WithMany("Medicines") .HasForeignKey("PharmacistId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Pharmacist"); }); modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => diff --git a/Hospital/HospitalDatabaseImplement/Models/Medicine.cs b/Hospital/HospitalDatabaseImplement/Models/Medicine.cs index 41e6575..ee2196b 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Medicine.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Medicine.cs @@ -12,8 +12,62 @@ using HospitalDatabaseImplement.Models; namespace HospitalDatabaseImplement.Models { - public class Medicine + public class Medicine : IMedicineModel { + + public int Id { get; set; } + [Required] + [MaxLength(50)] + public string Name { get; set; } = string.Empty; + + [Required] + + public string CountryOrigin { get; set; } = string.Empty; + [Required] + + public double Price { get; set; } + + public int PharmacistId { get; private set; } + + public virtual Pharmacist Pharmacist { get; set; } + + [ForeignKey("MedicineId")] + public virtual List RecipeMedicines { get; set; } = new(); + + public static Medicine? Create(MedicineBindingModel model) + { + if (model == null) + { + return null; + } + return new Medicine() + { + Id = model.Id, + Name = model.Name + }; + } + public static Medicine Create(MedicineViewModel model) + { + return new Medicine + { + Id = model.Id, + Name = model.Name + }; + } + public void Update(MedicineBindingModel model) + { + if (model == null) + { + return; + } + Name = model.Name; + } + public MedicineViewModel GetViewModel => new() + { + Id = Id, + Name = Name + }; + } } \ No newline at end of file diff --git a/Hospital/HospitalDatabaseImplement/Models/Procedure.cs b/Hospital/HospitalDatabaseImplement/Models/Procedure.cs index faa6171..67068bc 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Procedure.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Procedure.cs @@ -78,11 +78,7 @@ namespace HospitalDatabaseImplement.Models public int PharmacistId { get; private set; } public virtual Pharmacist Pharmacist { get; set; } - // public DateTime Date => throw new NotImplementedException(); - - //public int DescriptionOfTheProcedureId => throw new NotImplementedException(); - - // public int PharmacistId => throw new NotImplementedException(); + public void UpdateMedicines(HospitalDatabase context, ProcedureBindingModel model) {