From df2127107ff004fcaa7ea7237938c88ca51c0d33 Mon Sep 17 00:00:00 2001 From: Alenka Date: Mon, 29 Apr 2024 16:13:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=81=D0=BE=D0=B1?= =?UTF-8?q?=D0=B8=D1=80=D0=B0=D0=B5=D0=BC=20=D0=91=D0=94,=20=D1=83=D1=80?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Hospital/Properties/launchSettings.json | 12 + .../Properties/launchSettings.json | 12 + .../BindingModels/ProcedureBindingModel.cs | 2 +- .../Properties/launchSettings.json | 12 + .../ViewModels/ProcedureViewModel.cs | 2 +- .../HospitalDatabase.cs | 5 +- .../DescriptionProcedureStorage.cs | 120 ++++ .../Implementss/MedicineStorage.cs | 111 +++- .../Implementss/PharmacistStorage.cs | 115 ++++ .../20240429112728_Hospital.Designer.cs | 577 ++++++++++++++++++ .../Migrations/20240429112728_Hospital.cs | 173 ++++++ .../Models/DescriptionProcedure.cs | 69 +++ .../Properties/launchSettings.json | 12 + .../Models/IProcedureModel.cs | 2 +- .../Properties/launchSettings.json | 12 + .../Implementss/ProcedureStorage.cs | 4 +- .../HospitalDatabaseModelSnapshot.cs | 313 +++++++--- .../Models/Medicine.cs | 50 +- .../Models/Pharmacist.cs | 23 +- .../Models/Procedure.cs | 19 +- .../Models/ProcedureMedicine.cs | 5 +- 21 files changed, 1482 insertions(+), 168 deletions(-) create mode 100644 Hospital/Hospital/Properties/launchSettings.json create mode 100644 Hospital/HospitalBusinessLogic/Properties/launchSettings.json create mode 100644 Hospital/HospitalContracts/Properties/launchSettings.json create mode 100644 Hospital/HospitalDataBaseImplement/Implementss/DescriptionProcedureStorage.cs create mode 100644 Hospital/HospitalDataBaseImplement/Implementss/PharmacistStorage.cs create mode 100644 Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs create mode 100644 Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.cs create mode 100644 Hospital/HospitalDataBaseImplement/Models/DescriptionProcedure.cs create mode 100644 Hospital/HospitalDataBaseImplement/Properties/launchSettings.json create mode 100644 Hospital/HospitalDataModels/Properties/launchSettings.json diff --git a/Hospital/Hospital/Properties/launchSettings.json b/Hospital/Hospital/Properties/launchSettings.json new file mode 100644 index 0000000..c6467db --- /dev/null +++ b/Hospital/Hospital/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "HospitalView": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:51159;http://localhost:51164" + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalBusinessLogic/Properties/launchSettings.json b/Hospital/HospitalBusinessLogic/Properties/launchSettings.json new file mode 100644 index 0000000..b02e335 --- /dev/null +++ b/Hospital/HospitalBusinessLogic/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "HospitalBusinessLogic": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:51157;http://localhost:51163" + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalContracts/BindingModels/ProcedureBindingModel.cs b/Hospital/HospitalContracts/BindingModels/ProcedureBindingModel.cs index 1a6538c..8e06f9e 100644 --- a/Hospital/HospitalContracts/BindingModels/ProcedureBindingModel.cs +++ b/Hospital/HospitalContracts/BindingModels/ProcedureBindingModel.cs @@ -14,7 +14,7 @@ namespace HospitalContracts.BindingModels public DateTime Date { get; set; } - public int DescriptionOfTheProcedureId { get; set; } + public int DescriptionProcedureId { get; set; } public int PharmacistId { get; set; } diff --git a/Hospital/HospitalContracts/Properties/launchSettings.json b/Hospital/HospitalContracts/Properties/launchSettings.json new file mode 100644 index 0000000..1a944dd --- /dev/null +++ b/Hospital/HospitalContracts/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "HospitalContracts": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:51160;http://localhost:51162" + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs b/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs index 3fae7f3..a3fecec 100644 --- a/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs +++ b/Hospital/HospitalContracts/ViewModels/ProcedureViewModel.cs @@ -19,7 +19,7 @@ namespace HospitalContracts.ViewModels //public string PharmacistFIO { get; set; } = string.Empty; public int PharmacistId { get; set; } [DisplayName("Описание процедуры")] - public int DescriptionOfTheProcedureId { get; set; } + public int DescriptionProcedureId { get; set; } public Dictionary ProcedureMedicines { get; set; } = new(); } diff --git a/Hospital/HospitalDataBaseImplement/HospitalDatabase.cs b/Hospital/HospitalDataBaseImplement/HospitalDatabase.cs index 88efe75..227e6da 100644 --- a/Hospital/HospitalDataBaseImplement/HospitalDatabase.cs +++ b/Hospital/HospitalDataBaseImplement/HospitalDatabase.cs @@ -39,7 +39,8 @@ namespace HospitalDatabaseImplement public virtual DbSet RecipeMedicines { set; get; } public virtual DbSet ProcedureMedicines { set; get; } - - //TODO добавить сущности описание процедур и промежутучную сущость у фармацевта + public virtual DbSet Pharmacists { set; get; } + public virtual DbSet DescriptionProcedures { set; get; } + } } diff --git a/Hospital/HospitalDataBaseImplement/Implementss/DescriptionProcedureStorage.cs b/Hospital/HospitalDataBaseImplement/Implementss/DescriptionProcedureStorage.cs new file mode 100644 index 0000000..8ce5dda --- /dev/null +++ b/Hospital/HospitalDataBaseImplement/Implementss/DescriptionProcedureStorage.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace HospitalDatabaseImplement.Implements +{ + public class DescriptionProcedureStorage : IDescriptionProcedureStorage + { + public DescriptionProcedureViewModel? GetElement(DescriptionProcedureSearchModel model) + { + if (string.IsNullOrEmpty(model.Description) && !model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.DescriptionProcedures + .Include(x => x.Procedures) + .Include(x => x.Pharmacist) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Description) && x.Description == model.Description) || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(DescriptionProcedureSearchModel model) + { + using var context = new HospitalDatabase(); + if (string.IsNullOrEmpty(model.Description) && !model.Id.HasValue) + { + return context.DescriptionProcedures + .Include(x => x.Procedures) + .Include(x => x.Pharmacist) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.PharmacistId.HasValue) + { + return context.DescriptionProcedures + .Include(x => x.Procedures) + .Include(x => x.Pharmacist) + .Where(x => x.PharmacistId == model.PharmacistId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.DescriptionProcedures + .Include(x => x.Procedures) + .Include(x => x.Pharmacist) + .Select(x => x.GetViewModel) + .ToList(); + } + + public DescriptionProcedureViewModel? Insert(DescriptionProcedureBindingModel model) + { + var newDisease = DescriptionProcedure.Create(model); + if (newDisease == null) + { + return null; + } + using var context = new HospitalDatabase(); + context.DescriptionProcedures.Add(newDisease); + context.SaveChanges(); + return context.DescriptionProcedures + .Include(x => x.Procedures) + .Include(x => x.Pharmacist) + .FirstOrDefault(x => x.Id == newDisease.Id) + ?.GetViewModel; + } + + public DescriptionProcedureViewModel? Update(DescriptionProcedureBindingModel model) + { + using var context = new HospitalDatabase(); + var disease = context.DescriptionProcedures.FirstOrDefault(x => x.Id == model.Id); + if (disease == null) + { + return null; + } + disease.Update(model); + context.SaveChanges(); + return context.DescriptionProcedures + .Include(x => x.Procedures) + .Include(x => x.Pharmacist) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public DescriptionProcedureViewModel? Delete(DescriptionProcedureBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.DescriptionProcedures.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.DescriptionProcedures + .Include(x => x.Procedures) + .Include(x => x.Pharmacist) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.DescriptionProcedures.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } + } +} diff --git a/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs b/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs index 19dec6b..edba730 100644 --- a/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs +++ b/Hospital/HospitalDataBaseImplement/Implementss/MedicineStorage.cs @@ -7,12 +7,115 @@ using HospitalContracts.BindingModels; using HospitalContracts.SearchModels; using HospitalContracts.StoragesContracts; using HospitalContracts.ViewModels; +using Microsoft.EntityFrameworkCore; - -namespace HospitalDatabaseImplement.Implementss +namespace HospitalDatabaseImplement.Implements { - public class MedicineStorage + public class MedicineStorage : IMedicineStorage { - + public MedicineViewModel? GetElement(MedicineSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.Medicines + .Include(x => x.Pharmacist) + .Include(x => x.Procedures) + .ThenInclude(x => x.Recipe) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Name) && x.FIO == model.Name) + || (model.Id.HasValue && x.Id == model.Id)))?.GetViewModel; + } + + public List GetFilteredList(MedicineSearchModel model) + { + using var context = new HospitalDatabase(); + if (!string.IsNullOrEmpty(model.Name)) + { + return context.Medicines + .Include(x => x.Doctor) + .Include(x => x.Recipes) + .ThenInclude(x => x.Recipe) + .Where(x => (x.Id == model.Id)).ToList() + .Select(x => x.GetViewModel).ToList(); + } + else if (model.DoctorId.HasValue) + { + return context.Medicines + .Include(x => x.Doctor) + .Include(x => x.Recipes) + .ThenInclude(x => x.Recipe) + .Where(x => x.DoctorId == model.DoctorId) + .Select(x => x.GetViewModel).ToList(); + } + else + { + return new(); + } + } + + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.Medicines + .Include(x => x.Doctor) + .Include(x => x.Recipes) + .ThenInclude(x => x.Recipe).ToList() + .Select(x => x.GetViewModel).ToList(); + } + + public MedicineViewModel? Insert(MedicineBindingModel model) + { + using var context = new HospitalDatabase(); + var newPatient = Patient.Create(context, model); + if (newPatient == null) + { + return null; + } + context.Medicines.Add(newPatient); + context.SaveChanges(); + return newPatient.GetViewModel; + } + + public MedicineViewModel? Update(MedicineBindingModel model) + { + using var context = new HospitalDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var patient = context.Medicines.FirstOrDefault(rec => rec.Id == model.Id); + if (patient == null) + { + return null; + } + patient.Update(model); + context.SaveChanges(); + patient.UpdateRecipes(context, model); + transaction.Commit(); + return patient.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public MedicineViewModel? Delete(MedicineBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.Medicines + .Include(x => x.Doctor) + .Include(x => x.Recipes) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Patients.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/Hospital/HospitalDataBaseImplement/Implementss/PharmacistStorage.cs b/Hospital/HospitalDataBaseImplement/Implementss/PharmacistStorage.cs new file mode 100644 index 0000000..497617a --- /dev/null +++ b/Hospital/HospitalDataBaseImplement/Implementss/PharmacistStorage.cs @@ -0,0 +1,115 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; +using HospitalDatabaseImplement.Modelss; +using Microsoft.EntityFrameworkCore; + +namespace HospitalDatabaseImplement.Implements +{ + public class PharmacistStorage : IPharmacistStorage + { + public PharmacistViewModel? GetElement(PharmacistSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.Pharmacists + .Include(x => x.Medicines) + .Include(x => x.Procedures) + .Include(x => x.DescriptionProcedures) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFilteredList(PharmacistSearchModel model) + { + using var context = new HospitalDatabase(); + if (!string.IsNullOrEmpty(model.Login)) + { + return context.Pharmacists + .Include(x => x.Medicines) + .Include(x => x.Procedures) + .Include(x => x.DescriptionProcedures) + .Where(x => x.Login.Contains(model.Login)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.Pharmacists + .Include(x => x.Medicines) + .Include(x => x.Procedures) + .Include(x => x.DescriptionProcedures) + .Select(x => x.GetViewModel) + .ToList(); + } + + public PharmacistViewModel? Insert(PharmacistBindingModel model) + { + var newDoctor = Pharmacist.Create(model); + if (newDoctor == null) + { + return null; + } + using var context = new HospitalDatabase(); + context.Pharmacists.Add(newDoctor); + context.SaveChanges(); + return context.Pharmacists + .Include(x => x.Medicines) + .Include(x => x.Procedures) + .Include(x => x.DescriptionProcedures) + .FirstOrDefault(x => x.Id == newDoctor.Id) + ?.GetViewModel; + } + + public PharmacistViewModel? Update(PharmacistBindingModel model) + { + using var context = new HospitalDatabase(); + var doctor = context.Pharmacists.FirstOrDefault(x => x.Id == model.Id); + if (doctor == null) + { + return null; + } + doctor.Update(model); + context.SaveChanges(); + return context.Pharmacists + .Include(x => x.Medicines) + .Include(x => x.Procedures) + .Include(x => x.DescriptionProcedures) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public PharmacistViewModel? Delete(PharmacistBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.Pharmacists.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.Pharmacists + .Include(x => x.Medicines) + .Include(x => x.Procedures) + .Include(x => x.DescriptionProcedures) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.Pharmacists.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } + } +} diff --git a/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs b/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs new file mode 100644 index 0000000..32b6305 --- /dev/null +++ b/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.Designer.cs @@ -0,0 +1,577 @@ +// +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("20240429112728_Hospital")] + partial class Hospital + { + /// + 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.DescriptionProcedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("PharmacistId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PharmacistId"); + + b.ToTable("DescriptionProcedures"); + }); + + 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.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.HasIndex("PharmacistId"); + + b.ToTable("Medicines"); + }); + + 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.Pharmacist", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasMaxLength(55) + .HasColumnType("nvarchar(55)"); + + b.Property("Login") + .IsRequired() + .HasMaxLength(25) + .HasColumnType("nvarchar(25)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasMaxLength(11) + .HasColumnType("nvarchar(11)"); + + b.HasKey("Id"); + + b.ToTable("Pharmacists"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("DescriptionProcedureId") + .HasColumnType("int"); + + b.Property("IDescriptionProcedureId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PharmacistId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IDescriptionProcedureId"); + + b.HasIndex("PharmacistId"); + + b.ToTable("Procedures"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MedicineId") + .HasColumnType("int"); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MedicineId"); + + b.HasIndex("ProcedureId"); + + b.ToTable("ProcedureMedicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.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.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.DescriptionProcedure", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", "Pharmacist") + .WithMany("DescriptionProcedures") + .HasForeignKey("PharmacistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Pharmacist"); + }); + + 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.Medicine", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", null) + .WithMany("Medicines") + .HasForeignKey("PharmacistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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.Models.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.Procedure", b => + { + b.HasOne("HospitalDatabaseImplement.Models.DescriptionProcedure", "DescriptionProcedure") + .WithMany("Procedures") + .HasForeignKey("IDescriptionProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", "Pharmacist") + .WithMany("Procedures") + .HasForeignKey("PharmacistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DescriptionProcedure"); + + b.Navigation("Pharmacist"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine") + .WithMany() + .HasForeignKey("MedicineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.Models.Procedure", "Procedure") + .WithMany("Medicines") + .HasForeignKey("ProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Medicine"); + + b.Navigation("Procedure"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b => + { + b.HasOne("HospitalDatabaseImplement.Models.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.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.DescriptionProcedure", b => + { + b.Navigation("Procedures"); + }); + + 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.Medicine", b => + { + b.Navigation("RecipeMedicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => + { + b.Navigation("Procedures"); + + b.Navigation("Recipes"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Pharmacist", b => + { + b.Navigation("DescriptionProcedures"); + + b.Navigation("Medicines"); + + b.Navigation("Procedures"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.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.cs b/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.cs new file mode 100644 index 0000000..666d719 --- /dev/null +++ b/Hospital/HospitalDataBaseImplement/Migrations/20240429112728_Hospital.cs @@ -0,0 +1,173 @@ +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/Models/DescriptionProcedure.cs b/Hospital/HospitalDataBaseImplement/Models/DescriptionProcedure.cs new file mode 100644 index 0000000..f459973 --- /dev/null +++ b/Hospital/HospitalDataBaseImplement/Models/DescriptionProcedure.cs @@ -0,0 +1,69 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Modelss; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HospitalDataModels.Models; + +namespace HospitalDatabaseImplement.Models +{ + public class DescriptionProcedure : IDescriptionProcedureModel + { + public int Id { get; set; } + + public int PharmacistId { get; private set; } + + public virtual Pharmacist Pharmacist { get; set; } + + + [Required] + [MaxLength(150)] + public string Description { get; set; } = string.Empty; + + [ForeignKey("IDescriptionProcedureId")] + public virtual List Procedures { get; set; } = new(); + + public static DescriptionProcedure? Create(DescriptionProcedureBindingModel model) + { + if (model == null) + { + return null; + } + return new DescriptionProcedure() + { + Id = model.Id, + Description = model.Description, + PharmacistId = model.PharmacistId + }; + } + + public static DescriptionProcedure Create(DescriptionProcedureViewModel model) + { + return new DescriptionProcedure + { + Id = model.Id, + Description = model.Description + }; + } + + public void Update(DescriptionProcedureBindingModel model) + { + if (model == null) + { + return; + } + Description = model.Description; + } + + public DescriptionProcedureViewModel GetViewModel => new() + { + Id = Id, + Description = Description + }; + } +} diff --git a/Hospital/HospitalDataBaseImplement/Properties/launchSettings.json b/Hospital/HospitalDataBaseImplement/Properties/launchSettings.json new file mode 100644 index 0000000..a291623 --- /dev/null +++ b/Hospital/HospitalDataBaseImplement/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "HospitalDatabaseImplement": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:51158;http://localhost:51165" + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalDataModels/Models/IProcedureModel.cs b/Hospital/HospitalDataModels/Models/IProcedureModel.cs index 9a6deac..6718671 100644 --- a/Hospital/HospitalDataModels/Models/IProcedureModel.cs +++ b/Hospital/HospitalDataModels/Models/IProcedureModel.cs @@ -10,7 +10,7 @@ namespace HospitalDataModels.Models { string Name { get; } DateTime Date { get; } - int DescriptionOfTheProcedureId { get; } + int DescriptionProcedureId { get; } int PharmacistId { get; } Dictionary ProcedureMedicines { get; } diff --git a/Hospital/HospitalDataModels/Properties/launchSettings.json b/Hospital/HospitalDataModels/Properties/launchSettings.json new file mode 100644 index 0000000..8f6ae65 --- /dev/null +++ b/Hospital/HospitalDataModels/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "HospitalDataModels": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:51161;http://localhost:51166" + } + } +} \ No newline at end of file diff --git a/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs b/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs index 2094aaf..690fbaf 100644 --- a/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implementss/ProcedureStorage.cs @@ -2,7 +2,7 @@ using HospitalContracts.SearchModels; using HospitalContracts.StoragesContracts; using HospitalContracts.ViewModels; -using HospitalDatabaseImplement.Modelss; +using HospitalDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -10,7 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HospitalDatabaseImplement.Implementss +namespace HospitalDatabaseImplement.Implements { public class ProcedureStorage : IProcedureStorage { diff --git a/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs index 0ad6d37..c0c0254 100644 --- a/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs +++ b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs @@ -22,6 +22,29 @@ namespace HospitalDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("HospitalDatabaseImplement.Models.DescriptionProcedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + b.Property("PharmacistId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PharmacistId"); + + b.ToTable("DescriptionProcedures"); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => { b.Property("Id") @@ -88,6 +111,36 @@ namespace HospitalDatabaseImplement.Migrations b.ToTable("Doctors"); }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.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.HasIndex("PharmacistId"); + + b.ToTable("Medicines"); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => { b.Property("Id") @@ -165,6 +218,96 @@ namespace HospitalDatabaseImplement.Migrations b.ToTable("PatientRecipes"); }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Pharmacist", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FIO") + .IsRequired() + .HasMaxLength(55) + .HasColumnType("nvarchar(55)"); + + b.Property("Login") + .IsRequired() + .HasMaxLength(25) + .HasColumnType("nvarchar(25)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasMaxLength(11) + .HasColumnType("nvarchar(11)"); + + b.HasKey("Id"); + + b.ToTable("Pharmacists"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("DescriptionProcedureId") + .HasColumnType("int"); + + b.Property("IDescriptionProcedureId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("PharmacistId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("IDescriptionProcedureId"); + + b.HasIndex("PharmacistId"); + + b.ToTable("Procedures"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MedicineId") + .HasColumnType("int"); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MedicineId"); + + b.HasIndex("ProcedureId"); + + b.ToTable("ProcedureMedicines"); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b => { b.Property("Id") @@ -188,75 +331,6 @@ namespace HospitalDatabaseImplement.Migrations 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") @@ -287,6 +361,17 @@ namespace HospitalDatabaseImplement.Migrations b.ToTable("Recipes"); }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.DescriptionProcedure", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", "Pharmacist") + .WithMany("DescriptionProcedures") + .HasForeignKey("PharmacistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Pharmacist"); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => { b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") @@ -298,6 +383,15 @@ namespace HospitalDatabaseImplement.Migrations b.Navigation("Doctor"); }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", null) + .WithMany("Medicines") + .HasForeignKey("PharmacistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => { b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") @@ -317,7 +411,7 @@ namespace HospitalDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.HasOne("HospitalDatabaseImplement.Modelss.Procedure", "Procedure") + b.HasOne("HospitalDatabaseImplement.Models.Procedure", "Procedure") .WithMany("PatientProcedures") .HasForeignKey("ProcedureId") .OnDelete(DeleteBehavior.Cascade) @@ -347,9 +441,47 @@ namespace HospitalDatabaseImplement.Migrations b.Navigation("Recipe"); }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b => + { + b.HasOne("HospitalDatabaseImplement.Models.DescriptionProcedure", "DescriptionProcedure") + .WithMany("Procedures") + .HasForeignKey("IDescriptionProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.Models.Pharmacist", "Pharmacist") + .WithMany("Procedures") + .HasForeignKey("PharmacistId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DescriptionProcedure"); + + b.Navigation("Pharmacist"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine") + .WithMany() + .HasForeignKey("MedicineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.Models.Procedure", "Procedure") + .WithMany("Medicines") + .HasForeignKey("ProcedureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Medicine"); + + b.Navigation("Procedure"); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b => { - b.HasOne("HospitalDatabaseImplement.Modelss.Medicine", "Medicine") + b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine") .WithMany("RecipeMedicines") .HasForeignKey("MedicineId") .OnDelete(DeleteBehavior.Cascade) @@ -366,25 +498,6 @@ namespace HospitalDatabaseImplement.Migrations 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") @@ -404,6 +517,11 @@ namespace HospitalDatabaseImplement.Migrations b.Navigation("Doctor"); }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.DescriptionProcedure", b => + { + b.Navigation("Procedures"); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => { b.Navigation("Recipes"); @@ -418,6 +536,11 @@ namespace HospitalDatabaseImplement.Migrations b.Navigation("Recipes"); }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b => + { + b.Navigation("RecipeMedicines"); + }); + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => { b.Navigation("Procedures"); @@ -425,12 +548,16 @@ namespace HospitalDatabaseImplement.Migrations b.Navigation("Recipes"); }); - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.Medicine", b => + modelBuilder.Entity("HospitalDatabaseImplement.Models.Pharmacist", b => { - b.Navigation("RecipeMedicines"); + b.Navigation("DescriptionProcedures"); + + b.Navigation("Medicines"); + + b.Navigation("Procedures"); }); - modelBuilder.Entity("HospitalDatabaseImplement.Modelss.Procedure", b => + modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b => { b.Navigation("Medicines"); diff --git a/Hospital/HospitalDatabaseImplement/Models/Medicine.cs b/Hospital/HospitalDatabaseImplement/Models/Medicine.cs index b5de1e2..41e6575 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Medicine.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Medicine.cs @@ -10,54 +10,10 @@ using System.Text; using System.Threading.Tasks; using HospitalDatabaseImplement.Models; -namespace HospitalDatabaseImplement.Modelss +namespace HospitalDatabaseImplement.Models { - public class Medicine : IMedicineModel + public class Medicine { - public int Id { get; set; } - [Required] - [MaxLength(50)] - public string Name { get; set; } = string.Empty; - public string CountryOrigin { get; set; } = string.Empty; - public double Price { get; set; } - public int PharmacistId { 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/Pharmacist.cs b/Hospital/HospitalDatabaseImplement/Models/Pharmacist.cs index 661b7a7..1cedb6a 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Pharmacist.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Pharmacist.cs @@ -9,8 +9,9 @@ using System.Threading.Tasks; using HospitalContracts.BindingModels; using HospitalContracts.ViewModels; using HospitalDataModels.Models; +using HospitalDatabaseImplement.Models; -namespace HospitalDatabaseImplement.Modelss +namespace HospitalDatabaseImplement.Models { public class Pharmacist : IPharmacistModel { @@ -30,16 +31,16 @@ namespace HospitalDatabaseImplement.Modelss [MaxLength(30)] public string Password { get; set; } = string.Empty; - //[ForeignKey("PharmacistId")] - //public virtual List Patients { get; set; } = new(); + [ForeignKey("PharmacistId")] + public virtual List Medicines { get; set; } = new(); - //[ForeignKey("DoctorId")] - //public virtual List Recipes { get; set; } = new(); + [ForeignKey("PharmacistId")] + public virtual List Procedures { get; set; } = new(); - // [ForeignKey("DoctorId")] - // public virtual List Diseases { get; set; } = new(); + [ForeignKey("PharmacistId")] + public virtual List DescriptionProcedures { get; set; } = new(); - public static Pharmacist? Create(DoctorBindingModel model) + public static Pharmacist? Create(PharmacistBindingModel model) { if (model == null) { @@ -53,7 +54,7 @@ namespace HospitalDatabaseImplement.Modelss Password = model.Password }; } - public static Pharmacist Create(DoctorViewModel model) + public static Pharmacist Create(PharmacistViewModel model) { return new Pharmacist { @@ -63,7 +64,7 @@ namespace HospitalDatabaseImplement.Modelss Password = model.Password }; } - public void Update(DoctorBindingModel model) + public void Update(PharmacistBindingModel model) { if (model == null) { @@ -73,7 +74,7 @@ namespace HospitalDatabaseImplement.Modelss PhoneNumber = model.PhoneNumber; Password = model.Password; } - public DoctorViewModel GetViewModel => new() + public PharmacistViewModel GetViewModel => new() { Id = Id, Login = Login, diff --git a/Hospital/HospitalDatabaseImplement/Models/Procedure.cs b/Hospital/HospitalDatabaseImplement/Models/Procedure.cs index 24ecd34..faa6171 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Procedure.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Procedure.cs @@ -9,8 +9,9 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using HospitalDatabaseImplement.Modelss; -namespace HospitalDatabaseImplement.Modelss +namespace HospitalDatabaseImplement.Models { // TODO переделать под все необходимые атрибуты фармацевту public class Procedure : IProcedureModel @@ -21,6 +22,7 @@ namespace HospitalDatabaseImplement.Modelss [MaxLength(50)] public string Name { get; set; } = string.Empty; + [ForeignKey("ProcedureId")] public virtual List PatientProcedures { get; set; } = new(); @@ -66,12 +68,21 @@ namespace HospitalDatabaseImplement.Modelss Name = Name, ProcedureMedicines = ProcedureMedicines }; + [Required] + + public DateTime Date { get; set; } + [Required] + + public int DescriptionProcedureId { get; set; } + public virtual DescriptionProcedure DescriptionProcedure { get; set; } + public int PharmacistId { get; private set; } - public DateTime Date => throw new NotImplementedException(); + public virtual Pharmacist Pharmacist { get; set; } + // public DateTime Date => throw new NotImplementedException(); - public int DescriptionOfTheProcedureId => throw new NotImplementedException(); + //public int DescriptionOfTheProcedureId => throw new NotImplementedException(); - public int PharmacistId => throw new NotImplementedException(); + // public int PharmacistId => throw new NotImplementedException(); public void UpdateMedicines(HospitalDatabase context, ProcedureBindingModel model) { diff --git a/Hospital/HospitalDatabaseImplement/Models/ProcedureMedicine.cs b/Hospital/HospitalDatabaseImplement/Models/ProcedureMedicine.cs index 7f275a2..0486f17 100644 --- a/Hospital/HospitalDatabaseImplement/Models/ProcedureMedicine.cs +++ b/Hospital/HospitalDatabaseImplement/Models/ProcedureMedicine.cs @@ -1,11 +1,12 @@ -using System; +using HospitalDatabaseImplement.Models; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace HospitalDatabaseImplement.Modelss +namespace HospitalDatabaseImplement.Models { public class ProcedureMedicine {