From 2a52d1264d2c374d02e3697958ce6933149b1d45 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Fri, 7 Apr 2023 12:12:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=91=D0=94=20=D0=B8=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20Implements=20=D0=B2=20Hospital?= =?UTF-8?q?DatabaseImplement.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WeatherForecastController.cs | 33 -- Hospital/Hospital/Hospital.csproj | 12 + .../SearchModels/DiseaseSearchModel.cs | 2 + .../SearchModels/PatientSearchModel.cs | 2 + .../SearchModels/RecipeSearchModel.cs | 2 + .../Implements/DiseaseStorage.cs | 120 +++++ .../Implements/DoctorStorage.cs | 57 ++- .../Implements/MedicineStorage.cs | 101 ++++ .../Implements/PatientStorage.cs | 82 +++- .../Implements/ProcedureStorage.cs | 108 +++++ .../Implements/RecipeStorage.cs | 123 +++++ .../20230407075651_InitialCreate.Designer.cs | 431 ++++++++++++++++++ .../20230407075651_InitialCreate.cs | 325 +++++++++++++ .../HospitalDatabaseModelSnapshot.cs | 428 +++++++++++++++++ .../Models/Recipe.cs | 1 + 15 files changed, 1759 insertions(+), 68 deletions(-) delete mode 100644 Hospital/Hospital/Controllers/WeatherForecastController.cs create mode 100644 Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs create mode 100644 Hospital/HospitalDatabaseImplement/Implements/MedicineStorage.cs create mode 100644 Hospital/HospitalDatabaseImplement/Implements/ProcedureStorage.cs create mode 100644 Hospital/HospitalDatabaseImplement/Implements/RecipeStorage.cs create mode 100644 Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.Designer.cs create mode 100644 Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.cs create mode 100644 Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs diff --git a/Hospital/Hospital/Controllers/WeatherForecastController.cs b/Hospital/Hospital/Controllers/WeatherForecastController.cs deleted file mode 100644 index 43623c4..0000000 --- a/Hospital/Hospital/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Hospital.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() - { - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = Random.Shared.Next(-20, 55), - Summary = Summaries[Random.Shared.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} \ No newline at end of file diff --git a/Hospital/Hospital/Hospital.csproj b/Hospital/Hospital/Hospital.csproj index 60bf9ea..ac49f08 100644 --- a/Hospital/Hospital/Hospital.csproj +++ b/Hospital/Hospital/Hospital.csproj @@ -7,7 +7,19 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/Hospital/HospitalContracts/SearchModels/DiseaseSearchModel.cs b/Hospital/HospitalContracts/SearchModels/DiseaseSearchModel.cs index 107d58e..bdd6fb4 100644 --- a/Hospital/HospitalContracts/SearchModels/DiseaseSearchModel.cs +++ b/Hospital/HospitalContracts/SearchModels/DiseaseSearchModel.cs @@ -11,5 +11,7 @@ namespace HospitalContracts.SearchModels public int? Id { get; set; } public string? Name { get; set; } + + public int? DoctorId { get; set; } } } diff --git a/Hospital/HospitalContracts/SearchModels/PatientSearchModel.cs b/Hospital/HospitalContracts/SearchModels/PatientSearchModel.cs index c8e2df4..83b039f 100644 --- a/Hospital/HospitalContracts/SearchModels/PatientSearchModel.cs +++ b/Hospital/HospitalContracts/SearchModels/PatientSearchModel.cs @@ -15,5 +15,7 @@ namespace HospitalContracts.SearchModels public string? Name { get; set; } public string? Patronymic { get; set; } + + public int? DoctorId { get; set; } } } diff --git a/Hospital/HospitalContracts/SearchModels/RecipeSearchModel.cs b/Hospital/HospitalContracts/SearchModels/RecipeSearchModel.cs index 1a2f290..578c0fb 100644 --- a/Hospital/HospitalContracts/SearchModels/RecipeSearchModel.cs +++ b/Hospital/HospitalContracts/SearchModels/RecipeSearchModel.cs @@ -9,5 +9,7 @@ namespace HospitalContracts.SearchModels public class RecipeSearchModel { public int? Id { get; set; } + + public int? DoctorId { get; set; } } } diff --git a/Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs new file mode 100644 index 0000000..8f85df2 --- /dev/null +++ b/Hospital/HospitalDatabaseImplement/Implements/DiseaseStorage.cs @@ -0,0 +1,120 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDatabaseImplement.Implements +{ + public class DiseaseStorage : IDiseaseStorage + { + public DiseaseViewModel? GetElement(DiseaseSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.Diseases + .Include(x => x.Recipes) + .Include(x => x.Doctor) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(DiseaseSearchModel model) + { + using var context = new HospitalDatabase(); + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return context.Diseases + .Include(x => x.Recipes) + .Include(x => x.Doctor) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.DoctorId.HasValue) + { + return context.Diseases + .Include(x => x.Recipes) + .Include(x => x.Doctor) + .Where(x => x.DoctorId == model.DoctorId) + .Select(x => x.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.Diseases + .Include(x => x.Recipes) + .Include(x => x.Doctor) + .Select(x => x.GetViewModel) + .ToList(); + } + + public DiseaseViewModel? Insert(DiseaseBindingModel model) + { + var newDisease = Disease.Create(model); + if (newDisease == null) + { + return null; + } + using var context = new HospitalDatabase(); + context.Diseases.Add(newDisease); + context.SaveChanges(); + return context.Diseases + .Include(x => x.Recipes) + .Include(x => x.Doctor) + .FirstOrDefault(x => x.Id == newDisease.Id) + ?.GetViewModel; + } + + public DiseaseViewModel? Update(DiseaseBindingModel model) + { + using var context = new HospitalDatabase(); + var disease = context.Diseases.FirstOrDefault(x => x.Id == model.Id); + if (disease == null) + { + return null; + } + disease.Update(model); + context.SaveChanges(); + return context.Diseases + .Include(x => x.Recipes) + .Include(x => x.Doctor) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + } + + public DiseaseViewModel? Delete(DiseaseBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.Diseases.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + var deletedElement = context.Diseases + .Include(x => x.Recipes) + .Include(x => x.Doctor) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; + context.Diseases.Remove(element); + context.SaveChanges(); + return deletedElement; + } + return null; + } + } +} diff --git a/Hospital/HospitalDatabaseImplement/Implements/DoctorStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/DoctorStorage.cs index 1dc0c50..605a8e6 100644 --- a/Hospital/HospitalDatabaseImplement/Implements/DoctorStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implements/DoctorStorage.cs @@ -16,30 +16,44 @@ namespace HospitalDatabaseImplement.Implements { public DoctorViewModel? GetElement(DoctorSearchModel model) { - if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.PhoneNumber) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + if (!model.Id.HasValue) { return null; } using var context = new HospitalDatabase(); - return context.Doctors.FirstOrDefault(x =>(!string.IsNullOrEmpty(model.Login) && x.Login == model.Login && - !string.IsNullOrEmpty(model.PhoneNumber) && x.PhoneNumber == model.PhoneNumber && - !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Doctors + .Include(x => x.Recipes) + .Include(x => x.Diseases) + .Include(x => x.Patients) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; } public List GetFilteredList(DoctorSearchModel model) { - if (string.IsNullOrEmpty(model.Login)) - { - return new(); - } using var context = new HospitalDatabase(); - return context.Doctors.Where(x => x.Login.Contains(model.Login)).Select(x => x.GetViewModel).ToList(); + if (!string.IsNullOrEmpty(model.Login)) + { + return context.Doctors + .Include(x => x.Recipes) + .Include(x => x.Diseases) + .Include(x => x.Patients) + .Where(x => x.Login.Contains(model.Login)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); } public List GetFullList() { using var context = new HospitalDatabase(); - return context.Doctors.Select(x => x.GetViewModel).ToList(); + return context.Doctors + .Include(x => x.Recipes) + .Include(x => x.Diseases) + .Include(x => x.Patients) + .Select(x => x.GetViewModel) + .ToList(); } public DoctorViewModel? Insert(DoctorBindingModel model) @@ -52,7 +66,12 @@ namespace HospitalDatabaseImplement.Implements using var context = new HospitalDatabase(); context.Doctors.Add(newDoctor); context.SaveChanges(); - return newDoctor.GetViewModel; + return context.Doctors + .Include(x => x.Recipes) + .Include(x => x.Diseases) + .Include(x => x.Patients) + .FirstOrDefault(x => x.Id == newDoctor.Id) + ?.GetViewModel; } public DoctorViewModel? Update(DoctorBindingModel model) @@ -65,7 +84,12 @@ namespace HospitalDatabaseImplement.Implements } doctor.Update(model); context.SaveChanges(); - return doctor.GetViewModel; + return context.Doctors + .Include(x => x.Recipes) + .Include(x => x.Diseases) + .Include(x => x.Patients) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; } public DoctorViewModel? Delete(DoctorBindingModel model) @@ -74,10 +98,15 @@ namespace HospitalDatabaseImplement.Implements var element = context.Doctors.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { + var deletedElement = context.Doctors + .Include(x => x.Recipes) + .Include(x => x.Diseases) + .Include(x => x.Patients) + .FirstOrDefault(x => x.Id == model.Id) + ?.GetViewModel; context.Doctors.Remove(element); context.SaveChanges(); - - return element.GetViewModel; + return deletedElement; } return null; } diff --git a/Hospital/HospitalDatabaseImplement/Implements/MedicineStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/MedicineStorage.cs new file mode 100644 index 0000000..1564f34 --- /dev/null +++ b/Hospital/HospitalDatabaseImplement/Implements/MedicineStorage.cs @@ -0,0 +1,101 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDatabaseImplement.Implements +{ + public class MedicineStorage : IMedicineStorage + { + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.Medicines + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(MedicineSearchModel model) + { + using var context = new HospitalDatabase(); + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return context.Medicines + .Where(x => x.Name.Contains(model.Name)).ToList() + .Select(x => x.GetViewModel).ToList(); + } + else + { + return new(); + } + } + + public MedicineViewModel? GetElement(MedicineSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.Medicines + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public MedicineViewModel? Insert(MedicineBindingModel model) + { + using var context = new HospitalDatabase(); + var newMedicine = Medicine.Create(model); + if (newMedicine == null) + { + return null; + } + context.Medicines.Add(newMedicine); + context.SaveChanges(); + return newMedicine.GetViewModel; + } + + public MedicineViewModel? Update(MedicineBindingModel model) + { + using var context = new HospitalDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var medicine = context.Medicines + .FirstOrDefault(rec => rec.Id == model.Id); + if (medicine == null) + { + return null; + } + medicine.Update(model); + context.SaveChanges(); + transaction.Commit(); + return medicine.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public MedicineViewModel? Delete(MedicineBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.Medicines + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Medicines.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/Hospital/HospitalDatabaseImplement/Implements/PatientStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/PatientStorage.cs index d8b12c0..1ba9324 100644 --- a/Hospital/HospitalDatabaseImplement/Implements/PatientStorage.cs +++ b/Hospital/HospitalDatabaseImplement/Implements/PatientStorage.cs @@ -3,6 +3,7 @@ using HospitalContracts.SearchModels; using HospitalContracts.StoragesContracts; using HospitalContracts.ViewModels; using HospitalDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -20,62 +21,101 @@ namespace HospitalDatabaseImplement.Implements return null; } using var context = new HospitalDatabase(); - return context.Doctors.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login && - !string.IsNullOrEmpty(model.PhoneNumber) && x.PhoneNumber == model.PhoneNumber && - !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Patients + .Include(x => x.Doctor) + .Include(x => x.Recipes) + .ThenInclude(x => x.Recipe) + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Surname) && x.Surname == model.Surname) && + (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) && + (!string.IsNullOrEmpty(model.Patronymic) && x.Patronymic == model.Patronymic)) || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; } public List GetFilteredList(PatientSearchModel model) { - if (string.IsNullOrEmpty(model.Login)) + using var context = new HospitalDatabase(); + if (!string.IsNullOrEmpty(model.Surname) && !string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.Patronymic)) + { + return context.Patients + .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.Patients + .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(); } - using var context = new HospitalDatabase(); - return context.Doctors.Where(x => x.Login.Contains(model.Login)).Select(x => x.GetViewModel).ToList(); } public List GetFullList() { using var context = new HospitalDatabase(); - return context.Doctors.Select(x => x.GetViewModel).ToList(); + return context.Patients + .Include(x => x.Doctor) + .Include(x => x.Recipes) + .ThenInclude(x => x.Recipe).ToList() + .Select(x => x.GetViewModel).ToList(); } public PatientViewModel? Insert(PatientBindingModel model) { - var newDoctor = Doctor.Create(model); - if (newDoctor == null) + using var context = new HospitalDatabase(); + var newPatient = Patient.Create(context, model); + if (newPatient == null) { return null; } - using var context = new HospitalDatabase(); - context.Doctors.Add(newDoctor); + context.Patients.Add(newPatient); context.SaveChanges(); - return newDoctor.GetViewModel; + return newPatient.GetViewModel; } public PatientViewModel? Update(PatientBindingModel model) { using var context = new HospitalDatabase(); - var doctor = context.Doctors.FirstOrDefault(x => x.Id == model.Id); - if (doctor == null) + using var transaction = context.Database.BeginTransaction(); + try { - return null; + var patient = context.Patients.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; } - doctor.Update(model); - context.SaveChanges(); - return doctor.GetViewModel; } public PatientViewModel? Delete(PatientBindingModel model) { using var context = new HospitalDatabase(); - var element = context.Doctors.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Patients + .Include(x => x.Doctor) + .Include(x => x.Recipes) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { - context.Doctors.Remove(element); + context.Patients.Remove(element); context.SaveChanges(); - return element.GetViewModel; } return null; diff --git a/Hospital/HospitalDatabaseImplement/Implements/ProcedureStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/ProcedureStorage.cs new file mode 100644 index 0000000..690fbaf --- /dev/null +++ b/Hospital/HospitalDatabaseImplement/Implements/ProcedureStorage.cs @@ -0,0 +1,108 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDatabaseImplement.Implements +{ + public class ProcedureStorage : IProcedureStorage + { + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.Procedures + .Include(x => x.Medicines) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ProcedureSearchModel model) + { + using var context = new HospitalDatabase(); + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return context.Procedures + .Include(x => x.Medicines) + .Where(x => x.Name.Contains(model.Name)) + .Select(x => x.GetViewModel).ToList(); + } + else + { + return new(); + } + } + + public ProcedureViewModel? GetElement(ProcedureSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.Procedures + .Include(x => x.Medicines) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Name) && x.Name == model.Name) || (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ProcedureViewModel? Insert(ProcedureBindingModel model) + { + using var context = new HospitalDatabase(); + var newProcedure = Procedure.Create(context, model); + if (newProcedure == null) + { + return null; + } + context.Procedures.Add(newProcedure); + context.SaveChanges(); + return newProcedure.GetViewModel; + } + + public ProcedureViewModel? Update(ProcedureBindingModel model) + { + using var context = new HospitalDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var procedure = context.Procedures + .FirstOrDefault(rec => rec.Id == model.Id); + if (procedure == null) + { + return null; + } + procedure.Update(model); + context.SaveChanges(); + procedure.UpdateMedicines(context, model); + transaction.Commit(); + return procedure.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + + public ProcedureViewModel? Delete(ProcedureBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.Procedures + .Include(x => x.Medicines) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Procedures.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/Hospital/HospitalDatabaseImplement/Implements/RecipeStorage.cs b/Hospital/HospitalDatabaseImplement/Implements/RecipeStorage.cs new file mode 100644 index 0000000..1d92865 --- /dev/null +++ b/Hospital/HospitalDatabaseImplement/Implements/RecipeStorage.cs @@ -0,0 +1,123 @@ +using HospitalContracts.BindingModels; +using HospitalContracts.SearchModels; +using HospitalContracts.StoragesContracts; +using HospitalContracts.ViewModels; +using HospitalDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalDatabaseImplement.Implements +{ + public class RecipeStorage : IRecipeStorage + { + public List GetFullList() + { + using var context = new HospitalDatabase(); + return context.Recipes + .Include(x => x.Doctor) + .Include(x => x.DiseaseId) + .Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(RecipeSearchModel model) + { + using var context = new HospitalDatabase(); + if (!model.Id.HasValue) + { + return context.Recipes + .Include(x => x.Doctor) + .Include(x => x.Medicines) + .ThenInclude(x => x.Medicine) + .Where(x => x.Id == model.Id).ToList() + .Select(x => x.GetViewModel).ToList(); + } + else if (model.DoctorId.HasValue) + { + return context.Recipes + .Include(x => x.Doctor) + .Include(x => x.Medicines) + .ThenInclude(x => x.Medicine) + .Where(x => x.DoctorId == model.DoctorId) + .Select(x => x.GetViewModel).ToList(); + } + else + { + return new(); + } + } + + public RecipeViewModel? GetElement(RecipeSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new HospitalDatabase(); + return context.Recipes + .Include(x => x.Doctor) + .Include(x => x.Medicines) + .ThenInclude(x => x.Medicine) + .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + + public RecipeViewModel? Insert(RecipeBindingModel model) + { + using var context = new HospitalDatabase(); + var newRecipe = Recipe.Create(context, model); + if (newRecipe == null) + { + return null; + } + context.Recipes.Add(newRecipe); + context.SaveChanges(); + return newRecipe.GetViewModel; + } + + public RecipeViewModel? Update(RecipeBindingModel model) + { + using var context = new HospitalDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var recipe = context.Recipes + .Include(x => x.Doctor) + .FirstOrDefault(rec => rec.Id == model.Id); + if (recipe == null) + { + return null; + } + recipe.Update(model); + context.SaveChanges(); + recipe.UpdateMedicines(context, model); + transaction.Commit(); + return recipe.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public RecipeViewModel? Delete(RecipeBindingModel model) + { + using var context = new HospitalDatabase(); + var element = context.Recipes + .Include(x => x.Doctor) + .Include(x => x.Medicines) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Recipes.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.Designer.cs b/Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.Designer.cs new file mode 100644 index 0000000..93bf252 --- /dev/null +++ b/Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.Designer.cs @@ -0,0 +1,431 @@ +// +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("20230407075651_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DoctorId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Symptoms") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + 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("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("Doctors"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", 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("Medicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("DoctorId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Patronymic") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Surname") + .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.Procedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Procedures"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MedicineId") + .HasColumnType("int"); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MedicineId"); + + b.HasIndex("ProcedureId"); + + b.ToTable("ProcedureMedicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("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.RecipeMedicine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MedicineId") + .HasColumnType("int"); + + b.Property("RecipeId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MedicineId"); + + b.HasIndex("RecipeId"); + + b.ToTable("RecipeMedicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") + .WithMany("Diseases") + .HasForeignKey("DoctorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Doctor"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") + .WithMany("Patients") + .HasForeignKey("DoctorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Doctor"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientProcedure", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Patient", "Patient") + .WithMany("Procedures") + .HasForeignKey("PatientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.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.Models.Recipe", "Recipe") + .WithMany() + .HasForeignKey("RecipeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Patient"); + + b.Navigation("Recipe"); + }); + + 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.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.RecipeMedicine", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine") + .WithMany("RecipeMedicines") + .HasForeignKey("MedicineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.Models.Recipe", "Recipe") + .WithMany("Medicines") + .HasForeignKey("RecipeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Medicine"); + + b.Navigation("Recipe"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.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.Procedure", b => + { + b.Navigation("Medicines"); + + b.Navigation("PatientProcedures"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b => + { + b.Navigation("Medicines"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.cs b/Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.cs new file mode 100644 index 0000000..9d11b43 --- /dev/null +++ b/Hospital/HospitalDatabaseImplement/Migrations/20230407075651_InitialCreate.cs @@ -0,0 +1,325 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace HospitalDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Doctors", + 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), + 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_Doctors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Medicines", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Medicines", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Procedures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Procedures", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Diseases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DoctorId = table.Column(type: "int", nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Symptoms = table.Column(type: "nvarchar(150)", maxLength: 150, nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Diseases", x => x.Id); + table.ForeignKey( + name: "FK_Diseases_Doctors_DoctorId", + column: x => x.DoctorId, + principalTable: "Doctors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Patients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DoctorId = table.Column(type: "int", nullable: false), + Surname = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Name = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Patronymic = table.Column(type: "nvarchar(50)", maxLength: 50, nullable: false), + Age = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Patients", x => x.Id); + table.ForeignKey( + name: "FK_Patients_Doctors_DoctorId", + column: x => x.DoctorId, + principalTable: "Doctors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ProcedureMedicines", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ProcedureId = table.Column(type: "int", nullable: false), + MedicineId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProcedureMedicines", x => x.Id); + table.ForeignKey( + name: "FK_ProcedureMedicines_Medicines_MedicineId", + column: x => x.MedicineId, + principalTable: "Medicines", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ProcedureMedicines_Procedures_ProcedureId", + column: x => x.ProcedureId, + principalTable: "Procedures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Recipes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DoctorId = table.Column(type: "int", nullable: false), + DiseaseId = table.Column(type: "int", nullable: false), + IssueDate = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Recipes", x => x.Id); + table.ForeignKey( + name: "FK_Recipes_Diseases_DiseaseId", + column: x => x.DiseaseId, + principalTable: "Diseases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Recipes_Doctors_DoctorId", + column: x => x.DoctorId, + principalTable: "Doctors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PatientProcedures", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PatientId = table.Column(type: "int", nullable: false), + ProcedureId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PatientProcedures", x => x.Id); + table.ForeignKey( + name: "FK_PatientProcedures_Patients_PatientId", + column: x => x.PatientId, + principalTable: "Patients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PatientProcedures_Procedures_ProcedureId", + column: x => x.ProcedureId, + principalTable: "Procedures", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PatientRecipes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PatientId = table.Column(type: "int", nullable: false), + RecipeId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PatientRecipes", x => x.Id); + table.ForeignKey( + name: "FK_PatientRecipes_Patients_PatientId", + column: x => x.PatientId, + principalTable: "Patients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PatientRecipes_Recipes_RecipeId", + column: x => x.RecipeId, + principalTable: "Recipes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "RecipeMedicines", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + RecipeId = table.Column(type: "int", nullable: false), + MedicineId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RecipeMedicines", x => x.Id); + table.ForeignKey( + name: "FK_RecipeMedicines_Medicines_MedicineId", + column: x => x.MedicineId, + principalTable: "Medicines", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RecipeMedicines_Recipes_RecipeId", + column: x => x.RecipeId, + principalTable: "Recipes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Diseases_DoctorId", + table: "Diseases", + column: "DoctorId"); + + migrationBuilder.CreateIndex( + name: "IX_PatientProcedures_PatientId", + table: "PatientProcedures", + column: "PatientId"); + + migrationBuilder.CreateIndex( + name: "IX_PatientProcedures_ProcedureId", + table: "PatientProcedures", + column: "ProcedureId"); + + migrationBuilder.CreateIndex( + name: "IX_PatientRecipes_PatientId", + table: "PatientRecipes", + column: "PatientId"); + + migrationBuilder.CreateIndex( + name: "IX_PatientRecipes_RecipeId", + table: "PatientRecipes", + column: "RecipeId"); + + migrationBuilder.CreateIndex( + name: "IX_Patients_DoctorId", + table: "Patients", + column: "DoctorId"); + + migrationBuilder.CreateIndex( + name: "IX_ProcedureMedicines_MedicineId", + table: "ProcedureMedicines", + column: "MedicineId"); + + migrationBuilder.CreateIndex( + name: "IX_ProcedureMedicines_ProcedureId", + table: "ProcedureMedicines", + column: "ProcedureId"); + + migrationBuilder.CreateIndex( + name: "IX_RecipeMedicines_MedicineId", + table: "RecipeMedicines", + column: "MedicineId"); + + migrationBuilder.CreateIndex( + name: "IX_RecipeMedicines_RecipeId", + table: "RecipeMedicines", + column: "RecipeId"); + + migrationBuilder.CreateIndex( + name: "IX_Recipes_DiseaseId", + table: "Recipes", + column: "DiseaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Recipes_DoctorId", + table: "Recipes", + column: "DoctorId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "PatientProcedures"); + + migrationBuilder.DropTable( + name: "PatientRecipes"); + + migrationBuilder.DropTable( + name: "ProcedureMedicines"); + + migrationBuilder.DropTable( + name: "RecipeMedicines"); + + migrationBuilder.DropTable( + name: "Patients"); + + migrationBuilder.DropTable( + name: "Procedures"); + + migrationBuilder.DropTable( + name: "Medicines"); + + migrationBuilder.DropTable( + name: "Recipes"); + + migrationBuilder.DropTable( + name: "Diseases"); + + migrationBuilder.DropTable( + name: "Doctors"); + } + } +} diff --git a/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs new file mode 100644 index 0000000..f359a87 --- /dev/null +++ b/Hospital/HospitalDatabaseImplement/Migrations/HospitalDatabaseModelSnapshot.cs @@ -0,0 +1,428 @@ +// +using System; +using HospitalDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace HospitalDatabaseImplement.Migrations +{ + [DbContext(typeof(HospitalDatabase))] + partial class HospitalDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DoctorId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Symptoms") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("nvarchar(150)"); + + 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("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("Doctors"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", 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("Medicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Age") + .HasColumnType("int"); + + b.Property("DoctorId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Patronymic") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Surname") + .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.Procedure", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.ToTable("Procedures"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MedicineId") + .HasColumnType("int"); + + b.Property("ProcedureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MedicineId"); + + b.HasIndex("ProcedureId"); + + b.ToTable("ProcedureMedicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("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.RecipeMedicine", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MedicineId") + .HasColumnType("int"); + + b.Property("RecipeId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("MedicineId"); + + b.HasIndex("RecipeId"); + + b.ToTable("RecipeMedicines"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Disease", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") + .WithMany("Diseases") + .HasForeignKey("DoctorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Doctor"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Doctor", "Doctor") + .WithMany("Patients") + .HasForeignKey("DoctorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Doctor"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientProcedure", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Patient", "Patient") + .WithMany("Procedures") + .HasForeignKey("PatientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.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.Models.Recipe", "Recipe") + .WithMany() + .HasForeignKey("RecipeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Patient"); + + b.Navigation("Recipe"); + }); + + 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.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.RecipeMedicine", b => + { + b.HasOne("HospitalDatabaseImplement.Models.Medicine", "Medicine") + .WithMany("RecipeMedicines") + .HasForeignKey("MedicineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HospitalDatabaseImplement.Models.Recipe", "Recipe") + .WithMany("Medicines") + .HasForeignKey("RecipeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Medicine"); + + b.Navigation("Recipe"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.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.Procedure", b => + { + b.Navigation("Medicines"); + + b.Navigation("PatientProcedures"); + }); + + modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b => + { + b.Navigation("Medicines"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Hospital/HospitalDatabaseImplement/Models/Recipe.cs b/Hospital/HospitalDatabaseImplement/Models/Recipe.cs index bf087d6..7dd8222 100644 --- a/Hospital/HospitalDatabaseImplement/Models/Recipe.cs +++ b/Hospital/HospitalDatabaseImplement/Models/Recipe.cs @@ -8,6 +8,7 @@ using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Runtime.Serialization; namespace HospitalDatabaseImplement.Models {