diff --git a/HospitalContracts/BindingModels/RecipesBindingModel.cs b/HospitalContracts/BindingModels/RecipesBindingModel.cs index 089b438..70b6bf1 100644 --- a/HospitalContracts/BindingModels/RecipesBindingModel.cs +++ b/HospitalContracts/BindingModels/RecipesBindingModel.cs @@ -13,6 +13,7 @@ namespace HospitalContracts.BindingModels public string Dose { get; set; } = string.Empty; public DateTime Date { get; set; } = DateTime.Now; public string ModeOfApplication { get; set; } = string.Empty; + public int ClientId { get; set; } public int MedicinesId { get; set; } public Dictionary RecipeSymptoms { diff --git a/HospitalContracts/SearchModels/RecipesSearchModel.cs b/HospitalContracts/SearchModels/RecipesSearchModel.cs index ec0394d..ab06da7 100644 --- a/HospitalContracts/SearchModels/RecipesSearchModel.cs +++ b/HospitalContracts/SearchModels/RecipesSearchModel.cs @@ -9,5 +9,6 @@ namespace HospitalContracts.SearchModels public class RecipesSearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } } } diff --git a/HospitalContracts/ViewModels/RecipesViewModel.cs b/HospitalContracts/ViewModels/RecipesViewModel.cs index 00f65ad..d9e6ac6 100644 --- a/HospitalContracts/ViewModels/RecipesViewModel.cs +++ b/HospitalContracts/ViewModels/RecipesViewModel.cs @@ -11,10 +11,13 @@ namespace HospitalContracts.ViewModels public class RecipesViewModel: IRecipesModel { public int Id { get; set; } + public int ClientId { get; set; } [DisplayName("Доза")] public string Dose { get; set; } = string.Empty; [DisplayName("Дата выписки")] public DateTime Date { get; set; } + [DisplayName("Клиент")] + public string ClientFIO { get; set; } = string.Empty; [DisplayName("Способ приготовления")] public string ModeOfApplication { get; set; } = string.Empty; [DisplayName("Лекарство")] diff --git a/HospitalDataBaseImplements/HospitalDatabase.cs b/HospitalDataBaseImplements/HospitalDatabase.cs index 13ce24b..fa1502d 100644 --- a/HospitalDataBaseImplements/HospitalDatabase.cs +++ b/HospitalDataBaseImplements/HospitalDatabase.cs @@ -14,7 +14,7 @@ namespace HospitalDataBaseImplements { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-0BJHUJC\SQLEXPRESS;Initial Catalog=GiftShopDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-0BJHUJC\SQLEXPRESS;Initial Catalog=HospitalDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/HospitalDataBaseImplements/Implements/RecipesStorage.cs b/HospitalDataBaseImplements/Implements/RecipesStorage.cs index fdf2f72..b6ecabf 100644 --- a/HospitalDataBaseImplements/Implements/RecipesStorage.cs +++ b/HospitalDataBaseImplements/Implements/RecipesStorage.cs @@ -3,6 +3,7 @@ using HospitalContracts.SearchModels; using HospitalContracts.StoragesContracts; using HospitalContracts.ViewModels; using HospitalDataBaseImplements.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -33,7 +34,7 @@ namespace HospitalDataBaseImplements.Implements return null; } using var context = new HospitalDatabase(); - return context.Recipes.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Recipes.Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(RecipesSearchModel model) @@ -43,13 +44,13 @@ namespace HospitalDataBaseImplements.Implements return new(); } using var context = new HospitalDatabase(); - return context.Recipes.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + return context.Recipes.Include(x => x.Client).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); } public List GetFullList() { using var context = new HospitalDatabase(); - return context.Recipes.Select(x => x.GetViewModel).ToList(); + return context.Recipes.Include(x => x.Client).Select(x => x.GetViewModel).ToList(); } public RecipesViewModel? Insert(RecipesBindingModel model) diff --git a/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.Designer.cs b/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.Designer.cs new file mode 100644 index 0000000..2f36a4e --- /dev/null +++ b/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.Designer.cs @@ -0,0 +1,428 @@ +// +using System; +using HospitalDataBaseImplements; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace HospitalDataBaseImplements.Migrations +{ + [DbContext(typeof(HospitalDatabase))] + [Migration("20230406204404_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("HospitalDataBaseImplements.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Form") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IllnessName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Illnesses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessKurse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IllnessId") + .HasColumnType("int"); + + b.Property("KurseId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IllnessId"); + + b.HasIndex("KurseId"); + + b.ToTable("IllnessKurse"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessSymptoms", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IllnessId") + .HasColumnType("int"); + + b.Property("SymptomsId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IllnessId"); + + b.HasIndex("SymptomsId"); + + b.ToTable("IllnessSymptomses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountInDay") + .HasColumnType("int"); + + b.Property("Duration") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MedicinesId") + .HasColumnType("int"); + + b.Property("MedicinesName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("MedicinesId"); + + b.ToTable("Kurse"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Group") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MedicinesName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Medicines"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ProceduresName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Procedures"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Dose") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MedicinesId") + .HasColumnType("int"); + + b.Property("ModeOfApplication") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("MedicinesId"); + + b.ToTable("Recipes"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.Property("RecipesId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProcedureId"); + + b.HasIndex("RecipesId"); + + b.ToTable("RecipesProcedures"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RecipesId") + .HasColumnType("int"); + + b.Property("SymptomsId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RecipesId"); + + b.HasIndex("SymptomsId"); + + b.ToTable("RecipesSymptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("SymptomName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Symptomses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessKurse", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Illness", "Illness") + .WithMany("Kurses") + .HasForeignKey("IllnessId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Kurses", "Kurse") + .WithMany("IllnessKurses") + .HasForeignKey("KurseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Illness"); + + b.Navigation("Kurse"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessSymptoms", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Illness", "Illness") + .WithMany("Symptomses") + .HasForeignKey("IllnessId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms") + .WithMany("IllnessSymptomses") + .HasForeignKey("SymptomsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Illness"); + + b.Navigation("Symptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines") + .WithMany() + .HasForeignKey("MedicinesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Medicines"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Client", "Client") + .WithMany("Recipes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines") + .WithMany() + .HasForeignKey("MedicinesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Medicines"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Procedures", "Procedure") + .WithMany() + .HasForeignKey("ProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Recipes", "Recipe") + .WithMany("Procedures") + .HasForeignKey("RecipesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Procedure"); + + b.Navigation("Recipe"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Recipes", "Recipe") + .WithMany("Symptoms") + .HasForeignKey("RecipesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms") + .WithMany() + .HasForeignKey("SymptomsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recipe"); + + b.Navigation("Symptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Client", b => + { + b.Navigation("Recipes"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b => + { + b.Navigation("Kurses"); + + b.Navigation("Symptomses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b => + { + b.Navigation("IllnessKurses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => + { + b.Navigation("Procedures"); + + b.Navigation("Symptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b => + { + b.Navigation("IllnessSymptomses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.cs b/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.cs new file mode 100644 index 0000000..c8e20de --- /dev/null +++ b/HospitalDataBaseImplements/Migrations/20230406204404_InitialCreate.cs @@ -0,0 +1,333 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace HospitalDataBaseImplements.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Illnesses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + IllnessName = table.Column(type: "nvarchar(max)", nullable: false), + Form = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Illnesses", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Medicines", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + MedicinesName = table.Column(type: "nvarchar(max)", nullable: false), + Group = table.Column(type: "nvarchar(max)", 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"), + ProceduresName = table.Column(type: "nvarchar(max)", nullable: false), + Type = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Procedures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Symptomses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SymptomName = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Symptomses", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Kurse", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + MedicinesId = table.Column(type: "int", nullable: false), + MedicinesName = table.Column(type: "nvarchar(max)", nullable: false), + Duration = table.Column(type: "nvarchar(max)", nullable: false), + CountInDay = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Kurse", x => x.Id); + table.ForeignKey( + name: "FK_Kurse_Medicines_MedicinesId", + column: x => x.MedicinesId, + principalTable: "Medicines", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Recipes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Dose = table.Column(type: "nvarchar(max)", nullable: false), + Date = table.Column(type: "datetime2", nullable: false), + ClientId = table.Column(type: "int", nullable: false), + MedicinesId = table.Column(type: "int", nullable: false), + ModeOfApplication = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Recipes", x => x.Id); + table.ForeignKey( + name: "FK_Recipes_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Recipes_Medicines_MedicinesId", + column: x => x.MedicinesId, + principalTable: "Medicines", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "IllnessSymptomses", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + IllnessId = table.Column(type: "int", nullable: false), + SymptomsId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IllnessSymptomses", x => x.Id); + table.ForeignKey( + name: "FK_IllnessSymptomses_Illnesses_IllnessId", + column: x => x.IllnessId, + principalTable: "Illnesses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_IllnessSymptomses_Symptomses_SymptomsId", + column: x => x.SymptomsId, + principalTable: "Symptomses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "IllnessKurse", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + IllnessId = table.Column(type: "int", nullable: false), + KurseId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_IllnessKurse", x => x.Id); + table.ForeignKey( + name: "FK_IllnessKurse_Illnesses_IllnessId", + column: x => x.IllnessId, + principalTable: "Illnesses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_IllnessKurse_Kurse_KurseId", + column: x => x.KurseId, + principalTable: "Kurse", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "RecipesProcedures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RecipesId = table.Column(type: "int", nullable: false), + ProcedureId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RecipesProcedures", x => x.Id); + table.ForeignKey( + name: "FK_RecipesProcedures_Procedures_ProcedureId", + column: x => x.ProcedureId, + principalTable: "Procedures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RecipesProcedures_Recipes_RecipesId", + column: x => x.RecipesId, + principalTable: "Recipes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "RecipesSymptoms", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RecipesId = table.Column(type: "int", nullable: false), + SymptomsId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RecipesSymptoms", x => x.Id); + table.ForeignKey( + name: "FK_RecipesSymptoms_Recipes_RecipesId", + column: x => x.RecipesId, + principalTable: "Recipes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RecipesSymptoms_Symptomses_SymptomsId", + column: x => x.SymptomsId, + principalTable: "Symptomses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_IllnessKurse_IllnessId", + table: "IllnessKurse", + column: "IllnessId"); + + migrationBuilder.CreateIndex( + name: "IX_IllnessKurse_KurseId", + table: "IllnessKurse", + column: "KurseId"); + + migrationBuilder.CreateIndex( + name: "IX_IllnessSymptomses_IllnessId", + table: "IllnessSymptomses", + column: "IllnessId"); + + migrationBuilder.CreateIndex( + name: "IX_IllnessSymptomses_SymptomsId", + table: "IllnessSymptomses", + column: "SymptomsId"); + + migrationBuilder.CreateIndex( + name: "IX_Kurse_MedicinesId", + table: "Kurse", + column: "MedicinesId"); + + migrationBuilder.CreateIndex( + name: "IX_Recipes_ClientId", + table: "Recipes", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Recipes_MedicinesId", + table: "Recipes", + column: "MedicinesId"); + + migrationBuilder.CreateIndex( + name: "IX_RecipesProcedures_ProcedureId", + table: "RecipesProcedures", + column: "ProcedureId"); + + migrationBuilder.CreateIndex( + name: "IX_RecipesProcedures_RecipesId", + table: "RecipesProcedures", + column: "RecipesId"); + + migrationBuilder.CreateIndex( + name: "IX_RecipesSymptoms_RecipesId", + table: "RecipesSymptoms", + column: "RecipesId"); + + migrationBuilder.CreateIndex( + name: "IX_RecipesSymptoms_SymptomsId", + table: "RecipesSymptoms", + column: "SymptomsId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "IllnessKurse"); + + migrationBuilder.DropTable( + name: "IllnessSymptomses"); + + migrationBuilder.DropTable( + name: "RecipesProcedures"); + + migrationBuilder.DropTable( + name: "RecipesSymptoms"); + + migrationBuilder.DropTable( + name: "Kurse"); + + migrationBuilder.DropTable( + name: "Illnesses"); + + migrationBuilder.DropTable( + name: "Procedures"); + + migrationBuilder.DropTable( + name: "Recipes"); + + migrationBuilder.DropTable( + name: "Symptomses"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Medicines"); + } + } +} diff --git a/HospitalDataBaseImplements/Migrations/HospitalDatabaseModelSnapshot.cs b/HospitalDataBaseImplements/Migrations/HospitalDatabaseModelSnapshot.cs new file mode 100644 index 0000000..d8e57f7 --- /dev/null +++ b/HospitalDataBaseImplements/Migrations/HospitalDatabaseModelSnapshot.cs @@ -0,0 +1,425 @@ +// +using System; +using HospitalDataBaseImplements; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace HospitalDataBaseImplements.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("HospitalDataBaseImplements.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Form") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("IllnessName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Illnesses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessKurse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IllnessId") + .HasColumnType("int"); + + b.Property("KurseId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IllnessId"); + + b.HasIndex("KurseId"); + + b.ToTable("IllnessKurse"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessSymptoms", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IllnessId") + .HasColumnType("int"); + + b.Property("SymptomsId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IllnessId"); + + b.HasIndex("SymptomsId"); + + b.ToTable("IllnessSymptomses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CountInDay") + .HasColumnType("int"); + + b.Property("Duration") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MedicinesId") + .HasColumnType("int"); + + b.Property("MedicinesName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("MedicinesId"); + + b.ToTable("Kurse"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Medicines", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Group") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MedicinesName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Medicines"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Procedures", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ProceduresName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Procedures"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Dose") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MedicinesId") + .HasColumnType("int"); + + b.Property("ModeOfApplication") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("MedicinesId"); + + b.ToTable("Recipes"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.Property("RecipesId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProcedureId"); + + b.HasIndex("RecipesId"); + + b.ToTable("RecipesProcedures"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("RecipesId") + .HasColumnType("int"); + + b.Property("SymptomsId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RecipesId"); + + b.HasIndex("SymptomsId"); + + b.ToTable("RecipesSymptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("SymptomName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Symptomses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessKurse", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Illness", "Illness") + .WithMany("Kurses") + .HasForeignKey("IllnessId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Kurses", "Kurse") + .WithMany("IllnessKurses") + .HasForeignKey("KurseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Illness"); + + b.Navigation("Kurse"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.IllnessSymptoms", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Illness", "Illness") + .WithMany("Symptomses") + .HasForeignKey("IllnessId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms") + .WithMany("IllnessSymptomses") + .HasForeignKey("SymptomsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Illness"); + + b.Navigation("Symptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines") + .WithMany() + .HasForeignKey("MedicinesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Medicines"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Client", "Client") + .WithMany("Recipes") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Medicines", "Medicines") + .WithMany() + .HasForeignKey("MedicinesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Medicines"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesProcedures", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Procedures", "Procedure") + .WithMany() + .HasForeignKey("ProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Recipes", "Recipe") + .WithMany("Procedures") + .HasForeignKey("RecipesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Procedure"); + + b.Navigation("Recipe"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.RecipesSymptoms", b => + { + b.HasOne("HospitalDataBaseImplements.Models.Recipes", "Recipe") + .WithMany("Symptoms") + .HasForeignKey("RecipesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDataBaseImplements.Models.Symptoms", "Symptoms") + .WithMany() + .HasForeignKey("SymptomsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Recipe"); + + b.Navigation("Symptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Client", b => + { + b.Navigation("Recipes"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Illness", b => + { + b.Navigation("Kurses"); + + b.Navigation("Symptomses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Kurses", b => + { + b.Navigation("IllnessKurses"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Recipes", b => + { + b.Navigation("Procedures"); + + b.Navigation("Symptoms"); + }); + + modelBuilder.Entity("HospitalDataBaseImplements.Models.Symptoms", b => + { + b.Navigation("IllnessSymptomses"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/HospitalDataBaseImplements/Models/Client.cs b/HospitalDataBaseImplements/Models/Client.cs index 7e8db91..8460137 100644 --- a/HospitalDataBaseImplements/Models/Client.cs +++ b/HospitalDataBaseImplements/Models/Client.cs @@ -22,9 +22,7 @@ namespace HospitalDataBaseImplements.Models public string Password { get; set; } = string.Empty; [ForeignKey("ClientId")] - //public virtual List Medicines { get; set; } = new(); - //public virtual List Procedures { get; set; } = new(); - //public virtual List Recipes { get; set; } = new(); + public virtual List Recipes { get; set; } = new(); public static Client? Create(ClientBindingModel model) { diff --git a/HospitalDataBaseImplements/Models/Kurses.cs b/HospitalDataBaseImplements/Models/Kurses.cs index 48b5a1f..5325ee1 100644 --- a/HospitalDataBaseImplements/Models/Kurses.cs +++ b/HospitalDataBaseImplements/Models/Kurses.cs @@ -14,13 +14,16 @@ namespace HospitalDataBaseImplements.Models public class Kurses : IKurseModel { public int Id { get; private set; } + [ForeignKey("MedicinesId")] public int MedicinesId { get; private set; } + public virtual Medicines Medicines { get; set; } = new(); public string MedicinesName { get; private set; } = string.Empty; [Required] public string Duration { get; private set; } = string.Empty; [Required] public int CountInDay { get; private set; } - [ForeignKey("DrugCourseId")] + [ForeignKey("KurseId")] + public virtual List IllnessKurses { get; set; } = new(); public static Kurses? Create(KurseBindingModel model) { diff --git a/HospitalDataBaseImplements/Models/Medicines.cs b/HospitalDataBaseImplements/Models/Medicines.cs index c7e65e5..4bf7a87 100644 --- a/HospitalDataBaseImplements/Models/Medicines.cs +++ b/HospitalDataBaseImplements/Models/Medicines.cs @@ -4,6 +4,7 @@ using HospitalDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; diff --git a/HospitalDataBaseImplements/Models/Recipes.cs b/HospitalDataBaseImplements/Models/Recipes.cs index e072c21..e34b985 100644 --- a/HospitalDataBaseImplements/Models/Recipes.cs +++ b/HospitalDataBaseImplements/Models/Recipes.cs @@ -1,10 +1,13 @@ using HospitalContracts.BindingModels; using HospitalContracts.ViewModels; using HospitalDataModels.Models; +using Microsoft.EntityFrameworkCore.Query.Internal; +using Microsoft.Identity.Client; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using System.Dynamic; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -18,9 +21,13 @@ namespace HospitalDataBaseImplements.Models public string Dose { get; private set; } = string.Empty; [Required] public DateTime Date { get; private set; } = DateTime.Now; + [Required] + public int ClientId { get; set; } + public virtual Medicines Medicines { get; set; } = new(); public int MedicinesId { get; private set; } [Required] public string ModeOfApplication { get; private set; } = string.Empty; + public Client Client { get; set; } private Dictionary? _recipeProcedures = null; [NotMapped] public Dictionary RecipeProcedures @@ -30,12 +37,12 @@ namespace HospitalDataBaseImplements.Models if (_recipeProcedures == null) { _recipeProcedures = Procedures.ToDictionary(recPC => recPC.ProcedureId, recPC => - recPC.Procedures as IProceduresModel); + recPC.Procedure as IProceduresModel); } return _recipeProcedures; } } - [ForeignKey("ProceduresId")] + [ForeignKey("RecipesId")] public virtual List Procedures { get; set; } = new(); private Dictionary? _recipeSymptoms = null; @@ -51,7 +58,6 @@ namespace HospitalDataBaseImplements.Models return _recipeSymptoms; } } - [ForeignKey("SymptomsId")] public virtual List Symptoms { get; set; } = new(); public static Recipes Create(HospitalDatabase context, RecipesBindingModel model) @@ -61,9 +67,10 @@ namespace HospitalDataBaseImplements.Models Id = model.Id, Date = model.Date, MedicinesId = model.MedicinesId, + ClientId = model.ClientId, Procedures = model.RecipeProcedures.Select(x => new RecipesProcedures { - Procedures = context.Procedures.First(y => y.Id == x.Key), + Procedure = context.Procedures.First(y => y.Id == x.Key), }).ToList(), Symptoms = model.RecipeSymptoms.Select(x => new RecipesSymptoms { @@ -76,16 +83,24 @@ namespace HospitalDataBaseImplements.Models Date = model.Date; MedicinesId = model.MedicinesId; } - public RecipesViewModel GetViewModel => new() + public RecipesViewModel GetViewModel { - Id = Id, - Date = Date, - RecipeProcedures = RecipeProcedures, - RecipeSymptoms = RecipeSymptoms - }; + get { + using var context = new HospitalDatabase(); + return new RecipesViewModel + { + Id = Id, + Date = Date, + ClientId = ClientId, + ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty, + RecipeProcedures = RecipeProcedures, + RecipeSymptoms = RecipeSymptoms + }; + } + } public void UpdateProcedures(HospitalDatabase context, RecipesBindingModel model) { - var recipeProcedures = context.RecipesProcedures.Where(rec => rec.RecipeId == model.Id).ToList(); + var recipeProcedures = context.RecipesProcedures.Where(rec => rec.RecipesId == model.Id).ToList(); if (recipeProcedures != null && recipeProcedures.Count > 0) { // удалили те, которых нет в модели context.RecipesProcedures.RemoveRange(recipeProcedures.Where(rec @@ -97,8 +112,8 @@ namespace HospitalDataBaseImplements.Models { context.RecipesProcedures.Add(new RecipesProcedures { - Recipes = recipe, - Procedures = context.Procedures.First(x => x.Id == pc.Key) + Recipe = recipe, + Procedure = context.Procedures.First(x => x.Id == pc.Key) }); context.SaveChanges(); } @@ -106,7 +121,7 @@ namespace HospitalDataBaseImplements.Models } public void UpdateSymptomses(HospitalDatabase context, RecipesBindingModel model) { - var recipeSymptomses = context.RecipesSymptoms.Where(rec => rec.RecipeId == model.Id).ToList(); + var recipeSymptomses = context.RecipesSymptoms.Where(rec => rec.RecipesId == model.Id).ToList(); if (recipeSymptomses != null && recipeSymptomses.Count > 0) { // удалили те, которых нет в модели context.RecipesSymptoms.RemoveRange(recipeSymptomses.Where(rec @@ -118,7 +133,7 @@ namespace HospitalDataBaseImplements.Models { context.RecipesSymptoms.Add(new RecipesSymptoms { - Recipes = recipe, + Recipe = recipe, Symptoms = context.Symptomses.First(x => x.Id == pc.Key) }); context.SaveChanges(); diff --git a/HospitalDataBaseImplements/Models/RecipesProcedures.cs b/HospitalDataBaseImplements/Models/RecipesProcedures.cs index 62edea2..a4a84c9 100644 --- a/HospitalDataBaseImplements/Models/RecipesProcedures.cs +++ b/HospitalDataBaseImplements/Models/RecipesProcedures.cs @@ -11,10 +11,10 @@ namespace HospitalDataBaseImplements.Models { public int Id { get; set; } [Required] - public int RecipeId { get; set; } + public int RecipesId { get; set; } [Required] public int ProcedureId { get; set; } - public virtual Recipes Recipes { get; set; } = new(); - public virtual Procedures Procedures { get; set; } = new(); + public virtual Recipes Recipe { get; set; } = new(); + public virtual Procedures Procedure { get; set; } = new(); } } diff --git a/HospitalDataBaseImplements/Models/RecipesSymptoms.cs b/HospitalDataBaseImplements/Models/RecipesSymptoms.cs index 49e1184..5724437 100644 --- a/HospitalDataBaseImplements/Models/RecipesSymptoms.cs +++ b/HospitalDataBaseImplements/Models/RecipesSymptoms.cs @@ -11,10 +11,10 @@ namespace HospitalDataBaseImplements.Models { public int Id { get; set; } [Required] - public int RecipeId { get; set; } + public int RecipesId { get; set; } [Required] public int SymptomsId { get; set; } - public virtual Recipes Recipes { get; set; } = new(); + public virtual Recipes Recipe { get; set; } = new(); public virtual Symptoms Symptoms { get; set; } = new(); } } diff --git a/HospitalDataBaseImplements/Models/Symptoms.cs b/HospitalDataBaseImplements/Models/Symptoms.cs index d5c674c..bcc305b 100644 --- a/HospitalDataBaseImplements/Models/Symptoms.cs +++ b/HospitalDataBaseImplements/Models/Symptoms.cs @@ -17,10 +17,7 @@ namespace HospitalDataBaseImplements.Models [Required] public string SymptomName { get; set; } = string.Empty; public string? Description { get; set; } = string.Empty; - [ForeignKey("SymptomsId")] public virtual List IllnessSymptomses { get; set; } = new(); - [ForeignKey("SymptomsId")] - public virtual List Recipes { get; set; } = new(); public static Symptoms? Create(SymptomsBindingModel model) { if (model == null)