измененные миграции

This commit is contained in:
ValAnn 2024-04-29 20:45:10 +04:00
parent c43bf6c66d
commit 30ea05901a
7 changed files with 210 additions and 698 deletions

View File

@ -1,173 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace HospitalDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class Hospital : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "Date",
table: "Procedures",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<int>(
name: "DescriptionProcedureId",
table: "Procedures",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "IDescriptionProcedureId",
table: "Procedures",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "PharmacistId",
table: "Procedures",
type: "int",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "Pharmacists",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Login = table.Column<string>(type: "nvarchar(25)", maxLength: 25, nullable: false),
FIO = table.Column<string>(type: "nvarchar(55)", maxLength: 55, nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(11)", maxLength: 11, nullable: false),
Password = table.Column<string>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PharmacistId = table.Column<int>(type: "int", nullable: false),
Description = table.Column<string>(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);
}
/// <inheritdoc />
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");
}
}
}

View File

@ -1,450 +0,0 @@
// <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("20240429120033_CreateMigration")]
partial class CreateMigration
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Diseases");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Doctor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<string>("Login")
.IsRequired()
.HasMaxLength(25)
.HasColumnType("nvarchar(25)");
b.Property<string>("MailAddress")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasMaxLength(11)
.HasColumnType("nvarchar(11)");
b.HasKey("Id");
b.ToTable("Doctors");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<DateTime>("BirthDate")
.HasColumnType("datetime2");
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("FIO")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Patients");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientProcedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PatientId");
b.HasIndex("ProcedureId");
b.ToTable("PatientProcedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientRecipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<int>("RecipeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PatientId");
b.HasIndex("RecipeId");
b.ToTable("PatientRecipes");
});
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.Modelss.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("CountryOrigin")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<int>("PharmacistId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Medicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Modelss.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.Modelss.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.Modelss.Recipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("DiseaseId")
.HasColumnType("int");
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<DateTime>("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
}
}
}

View File

@ -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
{
/// <inheritdoc />
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 =>

View File

@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace HospitalDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class CreateMigration : Migration
public partial class InitialCreate : Migration
{
/// <inheritdoc />
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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
CountryOrigin = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
PharmacistId = table.Column<int>(type: "int", nullable: false)
Login = table.Column<string>(type: "nvarchar(25)", maxLength: 25, nullable: false),
FIO = table.Column<string>(type: "nvarchar(55)", maxLength: 55, nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(11)", maxLength: 11, nullable: false),
Password = table.Column<string>(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<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);
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<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)
PharmacistId = table.Column<int>(type: "int", nullable: false),
Description = table.Column<string>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
CountryOrigin = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
PharmacistId = table.Column<int>(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<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),
DescriptionProcedureId = table.Column<int>(type: "int", nullable: false),
IDescriptionProcedureId = table.Column<int>(type: "int", nullable: false),
PharmacistId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PatientId = table.Column<int>(type: "int", nullable: false),
RecipeId = table.Column<int>(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<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);
});
@ -181,62 +263,45 @@ namespace HospitalDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
name: "PatientRecipes",
name: "ProcedureMedicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PatientId = table.Column<int>(type: "int", nullable: false),
RecipeId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RecipeId = table.Column<int>(type: "int", nullable: false),
ProcedureId = 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.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");
}

View File

@ -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 =>

View File

@ -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<RecipeMedicine> 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
};
}
}

View File

@ -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)
{