Создание БД и реализация Implements в HospitalDatabaseImplement.

This commit is contained in:
Anastasia 2023-04-07 12:12:02 +04:00
parent 7e123f347a
commit 2a52d1264d
15 changed files with 1759 additions and 68 deletions

View File

@ -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<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> 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();
}
}
}

View File

@ -7,7 +7,19 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HospitalDatabaseImplement\HospitalDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -11,5 +11,7 @@ namespace HospitalContracts.SearchModels
public int? Id { get; set; }
public string? Name { get; set; }
public int? DoctorId { get; set; }
}
}

View File

@ -15,5 +15,7 @@ namespace HospitalContracts.SearchModels
public string? Name { get; set; }
public string? Patronymic { get; set; }
public int? DoctorId { get; set; }
}
}

View File

@ -9,5 +9,7 @@ namespace HospitalContracts.SearchModels
public class RecipeSearchModel
{
public int? Id { get; set; }
public int? DoctorId { get; set; }
}
}

View File

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

View File

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

View File

@ -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<MedicineViewModel> GetFullList()
{
using var context = new HospitalDatabase();
return context.Medicines
.Select(x => x.GetViewModel).ToList();
}
public List<MedicineViewModel> 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;
}
}
}

View File

@ -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<PatientViewModel> 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<PatientViewModel> 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;

View File

@ -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<ProcedureViewModel> GetFullList()
{
using var context = new HospitalDatabase();
return context.Procedures
.Include(x => x.Medicines)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ProcedureViewModel> 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;
}
}
}

View File

@ -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<RecipeViewModel> GetFullList()
{
using var context = new HospitalDatabase();
return context.Recipes
.Include(x => x.Doctor)
.Include(x => x.DiseaseId)
.Select(x => x.GetViewModel).ToList();
}
public List<RecipeViewModel> 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;
}
}
}

View File

@ -0,0 +1,431 @@
// <auto-generated />
using System;
using HospitalDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace HospitalDatabaseImplement.Migrations
{
[DbContext(typeof(HospitalDatabase))]
[Migration("20230407075651_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Symptoms")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Diseases");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Doctor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasMaxLength(25)
.HasColumnType("nvarchar(25)");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasMaxLength(11)
.HasColumnType("nvarchar(11)");
b.HasKey("Id");
b.ToTable("Doctors");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Medicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Age")
.HasColumnType("int");
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Patronymic")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Surname")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Patients");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientProcedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PatientId");
b.HasIndex("ProcedureId");
b.ToTable("PatientProcedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientRecipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<int>("RecipeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PatientId");
b.HasIndex("RecipeId");
b.ToTable("PatientRecipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Procedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DiseaseId")
.HasColumnType("int");
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<DateTime>("IssueDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("DiseaseId");
b.HasIndex("DoctorId");
b.ToTable("Recipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("RecipeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("RecipeId");
b.ToTable("RecipeMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.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
}
}
}

View File

@ -0,0 +1,325 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace HospitalDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Doctors",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Login = table.Column<string>(type: "nvarchar(25)", maxLength: 25, nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(11)", maxLength: 11, nullable: false),
Password = table.Column<string>(type: "nvarchar(30)", maxLength: 30, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Doctors", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Medicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Medicines", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Procedures",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Procedures", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Diseases",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DoctorId = table.Column<int>(type: "int", nullable: false),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Symptoms = table.Column<string>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DoctorId = table.Column<int>(type: "int", nullable: false),
Surname = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Name = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Patronymic = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
Age = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ProcedureId = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false)
},
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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DoctorId = table.Column<int>(type: "int", nullable: false),
DiseaseId = table.Column<int>(type: "int", nullable: false),
IssueDate = table.Column<DateTime>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PatientId = table.Column<int>(type: "int", nullable: false),
ProcedureId = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PatientId = table.Column<int>(type: "int", nullable: false),
RecipeId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PatientRecipes", x => x.Id);
table.ForeignKey(
name: "FK_PatientRecipes_Patients_PatientId",
column: x => x.PatientId,
principalTable: "Patients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PatientRecipes_Recipes_RecipeId",
column: x => x.RecipeId,
principalTable: "Recipes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "RecipeMedicines",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RecipeId = table.Column<int>(type: "int", nullable: false),
MedicineId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RecipeMedicines", x => x.Id);
table.ForeignKey(
name: "FK_RecipeMedicines_Medicines_MedicineId",
column: x => x.MedicineId,
principalTable: "Medicines",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RecipeMedicines_Recipes_RecipeId",
column: x => x.RecipeId,
principalTable: "Recipes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,428 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Symptoms")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("nvarchar(150)");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Diseases");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Doctor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasMaxLength(25)
.HasColumnType("nvarchar(25)");
b.Property<string>("Password")
.IsRequired()
.HasMaxLength(30)
.HasColumnType("nvarchar(30)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasMaxLength(11)
.HasColumnType("nvarchar(11)");
b.HasKey("Id");
b.ToTable("Doctors");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Medicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Medicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Patient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Age")
.HasColumnType("int");
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Patronymic")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.Property<string>("Surname")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.HasIndex("DoctorId");
b.ToTable("Patients");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientProcedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PatientId");
b.HasIndex("ProcedureId");
b.ToTable("PatientProcedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.PatientRecipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("PatientId")
.HasColumnType("int");
b.Property<int>("RecipeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("PatientId");
b.HasIndex("RecipeId");
b.ToTable("PatientRecipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Procedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("nvarchar(50)");
b.HasKey("Id");
b.ToTable("Procedures");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.ProcedureMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("ProcedureId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.Recipe", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("DiseaseId")
.HasColumnType("int");
b.Property<int>("DoctorId")
.HasColumnType("int");
b.Property<DateTime>("IssueDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.HasIndex("DiseaseId");
b.HasIndex("DoctorId");
b.ToTable("Recipes");
});
modelBuilder.Entity("HospitalDatabaseImplement.Models.RecipeMedicine", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("MedicineId")
.HasColumnType("int");
b.Property<int>("RecipeId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MedicineId");
b.HasIndex("RecipeId");
b.ToTable("RecipeMedicines");
});
modelBuilder.Entity("HospitalDatabaseImplement.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
}
}
}

View File

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