From 67f4dc1593663910c0fad8e6e29abddf8af4325c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D1=84=D1=8C=D1=8F=20=D0=AF=D0=BA=D0=BE=D0=B1?= =?UTF-8?q?=D1=87=D1=83=D0=BA?= Date: Mon, 27 May 2024 02:43:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B0=D0=B7=D0=B0=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B4=D0=BB=D1=8F=20=D0=98=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/CaseStorage.cs | 9 +- .../Implements/ExecutorStorage.cs | 76 ++- .../Implements/GuarantorStorage.cs | 181 +++--- .../Implements/VisitStorage.cs | 9 +- .../LawCompanyDatabase.cs | 2 +- .../20240526073959_test.Designer.cs | 543 ++++++++++++++++++ .../Migrations/20240526073959_test.cs | 412 +++++++++++++ .../20240526100556_test1.Designer.cs | 541 +++++++++++++++++ .../Migrations/20240526100556_test1.cs | 59 ++ .../20240526114610_test3.Designer.cs | 537 +++++++++++++++++ .../Migrations/20240526114610_test3.cs | 29 + .../LawCompanyDatabaseModelSnapshot.cs | 10 +- .../Models/Case.cs | 53 +- .../Models/Client.cs | 1 + .../Models/Visit.cs | 64 +-- 15 files changed, 2324 insertions(+), 202 deletions(-) create mode 100644 LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.Designer.cs create mode 100644 LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.cs create mode 100644 LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.Designer.cs create mode 100644 LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.cs create mode 100644 LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.Designer.cs create mode 100644 LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.cs diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs index e672228..74b0989 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/CaseStorage.cs @@ -93,8 +93,7 @@ namespace LawCompanyDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var _case = context.Cases.FirstOrDefault(rec => - rec.Id == model.Id); + var _case = context.Cases.FirstOrDefault(rec => rec.Id == model.Id); if (_case == null) { return null; @@ -102,21 +101,19 @@ namespace LawCompanyDatabaseImplement.Implements _case.Update(model); context.SaveChanges(); _case.UpdateClients(context, model); - transaction.Commit(); return _case.GetViewModel; } catch { + transaction.Rollback(); throw; } } public CaseViewModel? Delete(CaseBindingModel model) { using var context = new LawCompanyDatabase(); - var element = context.Cases - .Include(x => x.Clients) - .FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Cases.Include(x => x.Clients).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Cases.Remove(element); diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/ExecutorStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/ExecutorStorage.cs index 130f2ed..4741353 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/ExecutorStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/ExecutorStorage.cs @@ -3,6 +3,7 @@ using LawCompanyContracts.SearchModels; using LawCompanyContracts.StoragesContracts; using LawCompanyContracts.ViewModels; using LawCompanyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace LawCompanyDatabaseImplement.Implements { @@ -11,9 +12,7 @@ namespace LawCompanyDatabaseImplement.Implements public List GetFullList() { using var context = new LawCompanyDatabase(); - return context.Executors - .Select(x => x.GetViewModel) - .ToList(); + return context.Executors.Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(ExecutorSearchModel model) @@ -23,38 +22,53 @@ namespace LawCompanyDatabaseImplement.Implements { return new(); } - if (!string.IsNullOrEmpty(model.Email)) - { - using var context = new LawCompanyDatabase(); - return context.Executors - .Where(x => x.Email.Equals(model.Email)) - .Select(x => x.GetViewModel) - .ToList(); - } - else - { - using var context = new LawCompanyDatabase(); - return context.Executors - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - } + using var context = new LawCompanyDatabase(); + + return context.Executors + .Include(x => x.Cases) + .Include(x => x.Clients) + .Include(x => x.Visits) + .Where(x => x.Email.Contains(model.Email) && x.Password == model.Password) + .Select(x => x.GetViewModel) + .ToList(); + } public ExecutorViewModel? GetElement(ExecutorSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) - && string.IsNullOrEmpty(model.Password)) - { - return null; - } - using var context = new LawCompanyDatabase(); + using var context = new LawCompanyDatabase(); - return context.Executors - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) - && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } + if (model.Id.HasValue) + { + return context.Executors + .Include(x => x.Cases) + .Include(x => x.Clients) + .Include(x => x.Visits) + .FirstOrDefault(x => x.Id == model.Id)? + .GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + { + return context.Executors + .Include(x => x.Cases) + .Include(x => x.Clients) + .Include(x => x.Visits) + .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))? + .GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email)) + { + return context.Executors + .Include(x => x.Cases) + .Include(x => x.Clients) + .Include(x => x.Visits) + .FirstOrDefault(x => x.Email.Equals(model.Email))? + .GetViewModel; + } + + return null; + } public ExecutorViewModel? Insert(ExecutorBindingModel model) { diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs index b5d93e2..0260e9a 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/GuarantorStorage.cs @@ -3,96 +3,111 @@ using LawCompanyContracts.SearchModels; using LawCompanyContracts.StoragesContracts; using LawCompanyContracts.ViewModels; using LawCompanyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace LawCompanyDatabaseImplement.Implements { - public class GuarantorStorage : IGuarantorStorage - { - public List GetFullList() - { - using var context = new LawCompanyDatabase(); - return context.Guarantors - .Select(x => x.GetViewModel) - .ToList(); - } + public class GuarantorStorage : IGuarantorStorage + { + public List GetFullList() + { + using var context = new LawCompanyDatabase(); + return context.Guarantors.Select(x => x.GetViewModel).ToList(); + } - public List GetFilteredList(GuarantorSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) - && string.IsNullOrEmpty(model.Password)) - { - return new(); - } - if (!string.IsNullOrEmpty(model.Email)) - { - using var context = new LawCompanyDatabase(); - return context.Guarantors - .Where(x => x.Email.Equals(model.Email)) - .Select(x => x.GetViewModel) - .ToList(); - } - else - { - using var context = new LawCompanyDatabase(); - return context.Guarantors - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); - } - } + public List GetFilteredList(GuarantorSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.FIO) + && string.IsNullOrEmpty(model.Password)) + { + return new(); + } - public GuarantorViewModel? GetElement(GuarantorSearchModel model) - { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.FIO) - && string.IsNullOrEmpty(model.Password)) - { - return null; - } - using var context = new LawCompanyDatabase(); + using var context = new LawCompanyDatabase(); - return context.Guarantors - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) - && x.Email == model.Email) || (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; - } + return context.Guarantors + .Include(x => x.Consultations) + .Include(x => x.Lawyers) + .Include(x => x.Hearings) + .Where(x => x.Email.Contains(model.Email) && x.Password == model.Password) + .Select(x => x.GetViewModel) + .ToList(); + } - public GuarantorViewModel? Insert(GuarantorBindingModel model) - { - using var context = new LawCompanyDatabase(); - var newGuarantor = Guarantor.Create(context, model); - if (newGuarantor == null) - { - return null; - } - context.Guarantors.Add(newGuarantor); - context.SaveChanges(); - return newGuarantor.GetViewModel; - } + public GuarantorViewModel? GetElement(GuarantorSearchModel model) + { + using var context = new LawCompanyDatabase(); - public GuarantorViewModel? Update(GuarantorBindingModel model) - { - using var context = new LawCompanyDatabase(); - var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id); - if (executor == null) - { - return null; - } - executor.Update(model); - context.SaveChanges(); - return executor.GetViewModel; - } + if (model.Id.HasValue) + { + return context.Guarantors + .Include(x => x.Consultations) + .Include(x => x.Lawyers) + .Include(x => x.Hearings) + .FirstOrDefault(x => x.Id == model.Id)? + .GetViewModel; + } - public GuarantorViewModel? Delete(GuarantorBindingModel model) - { - using var context = new LawCompanyDatabase(); - var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Guarantors.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) + { + return context.Guarantors + .Include(x => x.Consultations) + .Include(x => x.Lawyers) + .Include(x => x.Hearings) + .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password))? + .GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email)) + { + return context.Guarantors + .Include(x => x.Consultations) + .Include(x => x.Lawyers) + .Include(x => x.Hearings) + .FirstOrDefault(x => x.Email.Equals(model.Email))? + .GetViewModel; + } + + return null; + } + + public GuarantorViewModel? Insert(GuarantorBindingModel model) + { + using var context = new LawCompanyDatabase(); + var newGuarantor = Guarantor.Create(context, model); + if (newGuarantor == null) + { + return null; + } + context.Guarantors.Add(newGuarantor); + context.SaveChanges(); + return newGuarantor.GetViewModel; + } + + public GuarantorViewModel? Update(GuarantorBindingModel model) + { + using var context = new LawCompanyDatabase(); + var executor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id); + if (executor == null) + { + return null; + } + executor.Update(model); + context.SaveChanges(); + return executor.GetViewModel; + } + + public GuarantorViewModel? Delete(GuarantorBindingModel model) + { + using var context = new LawCompanyDatabase(); + var element = context.Guarantors.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Guarantors.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } } diff --git a/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs b/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs index ac46a54..ca75e74 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Implements/VisitStorage.cs @@ -30,7 +30,7 @@ namespace LawCompanyDatabaseImplement.Implements { using var context = new LawCompanyDatabase(); return context.Visits - .Include(x => x.Clients).ThenInclude(x => x.Client) + .Include(x => x.Clients).ThenInclude(x => x.Client) .Where(x => x.ExecutorId == model.ExecutorId && x.VisitDate >= model.DateFrom && x.VisitDate <= model.DateTo) .Select(x => x.GetViewModel) .ToList(); @@ -121,8 +121,7 @@ namespace LawCompanyDatabaseImplement.Implements using var transaction = context.Database.BeginTransaction(); try { - var visit = context.Visits.FirstOrDefault(rec => - rec.Id == model.Id); + var visit = context.Visits.FirstOrDefault(rec => rec.Id == model.Id); if (visit == null) { return null; @@ -142,9 +141,7 @@ namespace LawCompanyDatabaseImplement.Implements public VisitViewModel? Delete(VisitBindingModel model) { using var context = new LawCompanyDatabase(); - var element = context.Visits - .Include(x => x.Clients) - .FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Visits.Include(x => x.Clients).FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Visits.Remove(element); diff --git a/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs b/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs index 8ed629b..c06f041 100644 --- a/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs +++ b/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabase.cs @@ -16,7 +16,7 @@ namespace LawCompanyDatabaseImplement if (optionsBuilder.IsConfigured == false) { //optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-6GNIALH9\SQLEXPRESS;Initial Catalog=LawCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-H8060U3\SQLEXPRESS;Initial Catalog=LawCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7DB3VEN\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.Designer.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.Designer.cs new file mode 100644 index 0000000..7df178b --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.Designer.cs @@ -0,0 +1,543 @@ +// +using System; +using LawCompanyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + [DbContext(typeof(LawCompanyDatabase))] + [Migration("20240526073959_test")] + partial class test + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("Cases"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("int"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("ClientId"); + + b.ToTable("CaseClients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("int"); + + b.Property("ConsultationDate") + .HasColumnType("datetime2"); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Consultations"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConsultationId") + .HasColumnType("int"); + + b.Property("LawyerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ConsultationId"); + + b.HasIndex("LawyerId"); + + b.ToTable("ConsultationLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Executors"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Guarantors"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("HearingDate") + .HasColumnType("datetime2"); + + b.Property("Judge") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Hearings"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("HearingId") + .HasColumnType("int"); + + b.Property("LawyerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("HearingId"); + + b.HasIndex("LawyerId"); + + b.ToTable("HearingLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("HearingId") + .HasColumnType("int"); + + b.Property("VisitDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.HasIndex("HearingId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("VisitId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("VisitId"); + + b.ToTable("VisitClients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Cases") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") + .WithMany("Clients") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") + .WithMany("CaseClients") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Clients") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") + .WithMany() + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Consultations") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Consultation", "Consultation") + .WithMany("Lawyers") + .HasForeignKey("ConsultationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") + .WithMany("ConsultationLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Consultation"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Hearings") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") + .WithMany("Lawyers") + .HasForeignKey("HearingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") + .WithMany("HearingLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Hearing"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Lawyers") + .HasForeignKey("GuarantorId"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Visits") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") + .WithMany() + .HasForeignKey("HearingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Hearing"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") + .WithMany("ClientVisits") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Visit", "Visit") + .WithMany("Clients") + .HasForeignKey("VisitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Visit"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.Navigation("Clients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.Navigation("CaseClients"); + + b.Navigation("ClientVisits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => + { + b.Navigation("Cases"); + + b.Navigation("Clients"); + + b.Navigation("Visits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => + { + b.Navigation("Consultations"); + + b.Navigation("Hearings"); + + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.Navigation("ConsultationLawyers"); + + b.Navigation("HearingLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.Navigation("Clients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.cs new file mode 100644 index 0000000..8e6c31f --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526073959_test.cs @@ -0,0 +1,412 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + /// + public partial class test : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Executors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Executors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Guarantors", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Guarantors", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Cases", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + CaseType = table.Column(type: "nvarchar(max)", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + Status = table.Column(type: "int", nullable: false), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Cases", x => x.Id); + table.ForeignKey( + name: "FK_Cases_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Phone = table.Column(type: "nvarchar(max)", nullable: false), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + table.ForeignKey( + name: "FK_Clients_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Hearings", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + HearingDate = table.Column(type: "datetime2", nullable: false), + Judge = table.Column(type: "nvarchar(max)", nullable: false), + GuarantorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Hearings", x => x.Id); + table.ForeignKey( + name: "FK_Hearings_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Lawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Phone = table.Column(type: "nvarchar(max)", nullable: false), + GuarantorId = table.Column(type: "int", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Lawyers", x => x.Id); + table.ForeignKey( + name: "FK_Lawyers_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Consultations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Cost = table.Column(type: "float", nullable: false), + ConsultationDate = table.Column(type: "datetime2", nullable: false), + CaseId = table.Column(type: "int", nullable: false), + GuarantorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Consultations", x => x.Id); + table.ForeignKey( + name: "FK_Consultations_Cases_CaseId", + column: x => x.CaseId, + principalTable: "Cases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Consultations_Guarantors_GuarantorId", + column: x => x.GuarantorId, + principalTable: "Guarantors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CaseClients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CaseId = table.Column(type: "int", nullable: false), + ClientId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CaseClients", x => x.Id); + table.ForeignKey( + name: "FK_CaseClients_Cases_CaseId", + column: x => x.CaseId, + principalTable: "Cases", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CaseClients_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "Visits", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + VisitDate = table.Column(type: "datetime2", nullable: false), + HearingId = table.Column(type: "int", nullable: false), + ExecutorId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Visits", x => x.Id); + table.ForeignKey( + name: "FK_Visits_Executors_ExecutorId", + column: x => x.ExecutorId, + principalTable: "Executors", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Visits_Hearings_HearingId", + column: x => x.HearingId, + principalTable: "Hearings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "HearingLawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + HearingId = table.Column(type: "int", nullable: false), + LawyerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_HearingLawyers", x => x.Id); + table.ForeignKey( + name: "FK_HearingLawyers_Hearings_HearingId", + column: x => x.HearingId, + principalTable: "Hearings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_HearingLawyers_Lawyers_LawyerId", + column: x => x.LawyerId, + principalTable: "Lawyers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "ConsultationLawyers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ConsultationId = table.Column(type: "int", nullable: false), + LawyerId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ConsultationLawyers", x => x.Id); + table.ForeignKey( + name: "FK_ConsultationLawyers_Consultations_ConsultationId", + column: x => x.ConsultationId, + principalTable: "Consultations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ConsultationLawyers_Lawyers_LawyerId", + column: x => x.LawyerId, + principalTable: "Lawyers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "VisitClients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), + VisitId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_VisitClients", x => x.Id); + table.ForeignKey( + name: "FK_VisitClients_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_VisitClients_Visits_VisitId", + column: x => x.VisitId, + principalTable: "Visits", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_CaseClients_CaseId", + table: "CaseClients", + column: "CaseId"); + + migrationBuilder.CreateIndex( + name: "IX_CaseClients_ClientId", + table: "CaseClients", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Cases_ExecutorId", + table: "Cases", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_Clients_ExecutorId", + table: "Clients", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_ConsultationLawyers_ConsultationId", + table: "ConsultationLawyers", + column: "ConsultationId"); + + migrationBuilder.CreateIndex( + name: "IX_ConsultationLawyers_LawyerId", + table: "ConsultationLawyers", + column: "LawyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Consultations_CaseId", + table: "Consultations", + column: "CaseId"); + + migrationBuilder.CreateIndex( + name: "IX_Consultations_GuarantorId", + table: "Consultations", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_HearingLawyers_HearingId", + table: "HearingLawyers", + column: "HearingId"); + + migrationBuilder.CreateIndex( + name: "IX_HearingLawyers_LawyerId", + table: "HearingLawyers", + column: "LawyerId"); + + migrationBuilder.CreateIndex( + name: "IX_Hearings_GuarantorId", + table: "Hearings", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_Lawyers_GuarantorId", + table: "Lawyers", + column: "GuarantorId"); + + migrationBuilder.CreateIndex( + name: "IX_VisitClients_ClientId", + table: "VisitClients", + column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_VisitClients_VisitId", + table: "VisitClients", + column: "VisitId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_ExecutorId", + table: "Visits", + column: "ExecutorId"); + + migrationBuilder.CreateIndex( + name: "IX_Visits_HearingId", + table: "Visits", + column: "HearingId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CaseClients"); + + migrationBuilder.DropTable( + name: "ConsultationLawyers"); + + migrationBuilder.DropTable( + name: "HearingLawyers"); + + migrationBuilder.DropTable( + name: "VisitClients"); + + migrationBuilder.DropTable( + name: "Consultations"); + + migrationBuilder.DropTable( + name: "Lawyers"); + + migrationBuilder.DropTable( + name: "Clients"); + + migrationBuilder.DropTable( + name: "Visits"); + + migrationBuilder.DropTable( + name: "Cases"); + + migrationBuilder.DropTable( + name: "Hearings"); + + migrationBuilder.DropTable( + name: "Executors"); + + migrationBuilder.DropTable( + name: "Guarantors"); + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.Designer.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.Designer.cs new file mode 100644 index 0000000..0f9f726 --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.Designer.cs @@ -0,0 +1,541 @@ +// +using System; +using LawCompanyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + [DbContext(typeof(LawCompanyDatabase))] + [Migration("20240526100556_test1")] + partial class test1 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("Cases"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("int"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("ClientId"); + + b.ToTable("CaseClients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("int"); + + b.Property("ConsultationDate") + .HasColumnType("datetime2"); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Consultations"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConsultationId") + .HasColumnType("int"); + + b.Property("LawyerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ConsultationId"); + + b.HasIndex("LawyerId"); + + b.ToTable("ConsultationLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Executors"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Guarantors"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("HearingDate") + .HasColumnType("datetime2"); + + b.Property("Judge") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Hearings"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("HearingId") + .HasColumnType("int"); + + b.Property("LawyerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("HearingId"); + + b.HasIndex("LawyerId"); + + b.ToTable("HearingLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("HearingId") + .HasColumnType("int"); + + b.Property("VisitDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.HasIndex("HearingId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("VisitId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("VisitId"); + + b.ToTable("VisitClients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Cases") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") + .WithMany("Clients") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") + .WithMany("CaseClients") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Clients") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") + .WithMany() + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Consultations") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Consultation", "Consultation") + .WithMany("Lawyers") + .HasForeignKey("ConsultationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") + .WithMany("ConsultationLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Consultation"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Hearings") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") + .WithMany("Lawyers") + .HasForeignKey("HearingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") + .WithMany("HearingLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Hearing"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Lawyers") + .HasForeignKey("GuarantorId"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Visits") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") + .WithMany() + .HasForeignKey("HearingId"); + + b.Navigation("Hearing"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") + .WithMany("ClientVisits") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Visit", "Visit") + .WithMany("Clients") + .HasForeignKey("VisitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Visit"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.Navigation("Clients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.Navigation("CaseClients"); + + b.Navigation("ClientVisits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => + { + b.Navigation("Cases"); + + b.Navigation("Clients"); + + b.Navigation("Visits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => + { + b.Navigation("Consultations"); + + b.Navigation("Hearings"); + + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.Navigation("ConsultationLawyers"); + + b.Navigation("HearingLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.Navigation("Clients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.cs new file mode 100644 index 0000000..1eed206 --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526100556_test1.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + /// + public partial class test1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Visits_Hearings_HearingId", + table: "Visits"); + + migrationBuilder.AlterColumn( + name: "HearingId", + table: "Visits", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Visits_Hearings_HearingId", + table: "Visits", + column: "HearingId", + principalTable: "Hearings", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Visits_Hearings_HearingId", + table: "Visits"); + + migrationBuilder.AlterColumn( + name: "HearingId", + table: "Visits", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Visits_Hearings_HearingId", + table: "Visits", + column: "HearingId", + principalTable: "Hearings", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.Designer.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.Designer.cs new file mode 100644 index 0000000..3de4286 --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.Designer.cs @@ -0,0 +1,537 @@ +// +using System; +using LawCompanyDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + [DbContext(typeof(LawCompanyDatabase))] + [Migration("20240526114610_test3")] + partial class test3 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Status") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("Cases"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("int"); + + b.Property("ClientId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("ClientId"); + + b.ToTable("CaseClients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("int"); + + b.Property("ConsultationDate") + .HasColumnType("datetime2"); + + b.Property("Cost") + .HasColumnType("float"); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Consultations"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConsultationId") + .HasColumnType("int"); + + b.Property("LawyerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ConsultationId"); + + b.HasIndex("LawyerId"); + + b.ToTable("ConsultationLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Executors"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Guarantors"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("HearingDate") + .HasColumnType("datetime2"); + + b.Property("Judge") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Hearings"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("HearingId") + .HasColumnType("int"); + + b.Property("LawyerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("HearingId"); + + b.HasIndex("LawyerId"); + + b.ToTable("HearingLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("FIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("GuarantorId") + .HasColumnType("int"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("GuarantorId"); + + b.ToTable("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ExecutorId") + .HasColumnType("int"); + + b.Property("HearingId") + .HasColumnType("int"); + + b.Property("VisitDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("ExecutorId"); + + b.HasIndex("HearingId"); + + b.ToTable("Visits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("VisitId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("VisitId"); + + b.ToTable("VisitClients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Cases") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.CaseClient", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") + .WithMany("Clients") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") + .WithMany("CaseClients") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Clients") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Case", "Case") + .WithMany() + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Consultations") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.ConsultationLawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Consultation", "Consultation") + .WithMany("Lawyers") + .HasForeignKey("ConsultationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") + .WithMany("ConsultationLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Consultation"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Hearings") + .HasForeignKey("GuarantorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.HearingLawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") + .WithMany("Lawyers") + .HasForeignKey("HearingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Lawyer", "Lawyer") + .WithMany("HearingLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Hearing"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Guarantor", null) + .WithMany("Lawyers") + .HasForeignKey("GuarantorId"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Executor", null) + .WithMany("Visits") + .HasForeignKey("ExecutorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") + .WithMany() + .HasForeignKey("HearingId"); + + b.Navigation("Hearing"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.VisitClient", b => + { + b.HasOne("LawCompanyDatabaseImplement.Models.Client", "Client") + .WithMany("ClientVisits") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("LawCompanyDatabaseImplement.Models.Visit", "Visit") + .WithMany("Clients") + .HasForeignKey("VisitId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Visit"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Case", b => + { + b.Navigation("Clients"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Client", b => + { + b.Navigation("CaseClients"); + + b.Navigation("ClientVisits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Consultation", b => + { + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Executor", b => + { + b.Navigation("Cases"); + + b.Navigation("Clients"); + + b.Navigation("Visits"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Guarantor", b => + { + b.Navigation("Consultations"); + + b.Navigation("Hearings"); + + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Hearing", b => + { + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Lawyer", b => + { + b.Navigation("ConsultationLawyers"); + + b.Navigation("HearingLawyers"); + }); + + modelBuilder.Entity("LawCompanyDatabaseImplement.Models.Visit", b => + { + b.Navigation("Clients"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.cs new file mode 100644 index 0000000..ed96605 --- /dev/null +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/20240526114610_test3.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LawCompanyDatabaseImplement.Migrations +{ + /// + public partial class test3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CaseType", + table: "Cases"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CaseType", + table: "Cases", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs b/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs index fc1ed55..cf6f047 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Migrations/LawCompanyDatabaseModelSnapshot.cs @@ -30,10 +30,6 @@ namespace LawCompanyDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - b.Property("CaseType") - .IsRequired() - .HasColumnType("nvarchar(max)"); - b.Property("DateCreate") .HasColumnType("datetime2"); @@ -301,7 +297,7 @@ namespace LawCompanyDatabaseImplement.Migrations b.Property("ExecutorId") .HasColumnType("int"); - b.Property("HearingId") + b.Property("HearingId") .HasColumnType("int"); b.Property("VisitDate") @@ -457,9 +453,7 @@ namespace LawCompanyDatabaseImplement.Migrations b.HasOne("LawCompanyDatabaseImplement.Models.Hearing", "Hearing") .WithMany() - .HasForeignKey("HearingId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("HearingId"); b.Navigation("Hearing"); }); diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs index fcf778d..3b3c2eb 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Case.cs @@ -13,8 +13,6 @@ namespace LawCompanyDatabaseImplement.Models [Required] public string Name { get; private set; } = String.Empty; [Required] - public string CaseType { get; private set; } = String.Empty; - [Required] public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } [Required] @@ -29,9 +27,7 @@ namespace LawCompanyDatabaseImplement.Models { if (_caseClients == null) { - using var context = new LawCompanyDatabase(); - _caseClients = Clients - .ToDictionary(x => x.ClientId, x => (context.Clients.FirstOrDefault(y => y.Id == x.ClientId) as IClientModel)); + _caseClients = Clients.ToDictionary(x => x.ClientId, x => (x.Client as IClientModel)); } return _caseClients; @@ -41,10 +37,6 @@ namespace LawCompanyDatabaseImplement.Models public virtual List Clients { get; set; } = new(); public static Case Create(LawCompanyDatabase context, CaseBindingModel model) { - if (model == null) - { - return null; - } return new Case() { Id = model.Id, @@ -59,54 +51,57 @@ namespace LawCompanyDatabaseImplement.Models }).ToList() }; } - public void Update(CaseBindingModel? model) + public void Update(CaseBindingModel model) { - using var context = new LawCompanyDatabase(); - if (model == null) + if (model.Status == CaseStatus.ЗакрытиеДела) { - return; + DateImplement = DateTime.Now; } - if (model.Status == CaseStatus.ЗакрытиеДела) DateImplement = DateTime.Now; Name = model.Name; Status = model.Status; - if (model.DateImplement.HasValue) DateImplement = model.DateImplement; + if (model.DateImplement.HasValue) + { + DateImplement = model.DateImplement; + } } + public CaseViewModel GetViewModel => new() { Id = Id, Name = Name, - CaseType = CaseType, DateCreate = DateCreate, DateImplement = DateImplement, ExecutorId = ExecutorId, Status = Status, - CaseClients = CaseClients, }; - public void UpdateClients(LawCompanyDatabase context, CaseBindingModel model) { - var caseClients = context.CaseClients.Where(rec => - rec.CaseId == model.Id).ToList(); + var caseClients = context.CaseClients.Where(rec => rec.CaseId == model.Id).ToList(); + if (caseClients != null && caseClients.Count > 0) { // удалили те, которых нет в модели - context.CaseClients.RemoveRange(caseClients.Where(rec - => !model.CaseClients.ContainsKey(rec.ClientId))); + context.CaseClients.RemoveRange(caseClients.Where(rec => !model.CaseClients.ContainsKey(rec.ClientId))); + context.SaveChanges(); + + foreach (var updateLunch in caseClients) + { + model.CaseClients.Remove(updateLunch.ClientId); + } context.SaveChanges(); } + var _case = context.Cases.First(x => x.Id == Id); + foreach (var pc in model.CaseClients) { - if (!CaseClients.ContainsKey(pc.Key)) + context.CaseClients.Add(new CaseClient { - context.CaseClients.Add(new CaseClient - { - Case = _case, - Client = context.Clients.First(x => x.Id == pc.Key), - }); - } + Case = _case, + Client = context.Clients.First(x => x.Id == pc.Key), + }); context.SaveChanges(); } _caseClients = null; diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs index ce016c3..96dc66a 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Client.cs @@ -20,6 +20,7 @@ namespace LawCompanyDatabaseImplement.Models [ForeignKey("ClientId")] public virtual List ClientVisits { get; set; } = new(); public int ExecutorId { get; set; } + public virtual Executor Executor { get; set; } public static Client? Create(ClientBindingModel? model) { diff --git a/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs b/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs index 373dec9..e4fce4c 100644 --- a/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs +++ b/LawCompany/LawCompanyDatabaseImplement/Models/Visit.cs @@ -13,12 +13,13 @@ namespace LawCompanyDatabaseImplement.Models public DateTime VisitDate { get; private set; } //связь один-к-одному - public int HearingId { get; private set; } + public int? HearingId { get; private set; } public Hearing Hearing { get; set; } = null!; //--- public int ExecutorId { get; set; } private Dictionary? _visitClients = null; + [NotMapped] public Dictionary VisitClients { @@ -27,82 +28,69 @@ namespace LawCompanyDatabaseImplement.Models if (_visitClients == null) { - using var context = new LawCompanyDatabase(); - _visitClients = Clients - .ToDictionary(x => x.ClientId, x => (context.Clients - .FirstOrDefault(y => y.Id == x.ClientId) as IClientModel)); + _visitClients = Clients.ToDictionary(x => x.ClientId, x => (x.Client as IClientModel)); } return _visitClients; } } + [ForeignKey("VisitId")] public virtual List Clients { get; set; } = new(); - public static Visit? Create(LawCompanyDatabase context, VisitBindingModel? model) + + public static Visit Create(LawCompanyDatabase context, VisitBindingModel model) { - if (model == null) - { - return null; - } - var visits = context.Visits.Where(x => x.HearingId == model.HearingId).ToList(); - if (visits.Count > 0) - { - return null; - } return new Visit() { Id = model.Id, VisitDate = model.VisitDate, HearingId = model.HearingId, ExecutorId = model.ExecutorId, - Hearing = context.Hearings.First(x => x.Id == model.HearingId), Clients = model.VisitClients.Select(x => new VisitClient { Client = context.Clients.First(y => y.Id == x.Key) }).ToList() }; } - public void Update(VisitBindingModel? model) + + public void Update(VisitBindingModel model) { - using var context = new LawCompanyDatabase(); - - if (model == null) - { - return; - } - VisitDate = model.VisitDate; HearingId = model.HearingId; } + public VisitViewModel GetViewModel => new() { Id = Id, VisitDate = VisitDate, HearingId = HearingId, - VisitClients = VisitClients, ExecutorId = ExecutorId, }; - public void UpdateClients(LawCompanyDatabase context, - VisitBindingModel model) + + public void UpdateClients(LawCompanyDatabase context, VisitBindingModel model) { - var visitClients = context.VisitClients.Where(rec => - rec.VisitId == model.Id).ToList(); + var visitClients = context.VisitClients.Where(rec => rec.VisitId == model.Id).ToList(); + if (visitClients != null && visitClients.Count > 0) { // удалили те, которых нет в модели - context.VisitClients.RemoveRange(visitClients.Where(rec - => !model.VisitClients.ContainsKey(rec.ClientId))); + context.VisitClients.RemoveRange(visitClients.Where(rec => !model.VisitClients.ContainsKey(rec.ClientId))); + context.SaveChanges(); + + foreach (var updateLunch in visitClients) + { + model.VisitClients.Remove(updateLunch.ClientId); + } context.SaveChanges(); } + var _visit = context.Visits.First(x => x.Id == Id); + foreach (var pc in model.VisitClients) { - if (!VisitClients.ContainsKey(pc.Key)) + context.VisitClients.Add(new VisitClient { - context.VisitClients.Add(new VisitClient - { - Visit = _visit, - Client = context.Clients.First(x => x.Id == pc.Key), - }); - } + Visit = _visit, + Client = context.Clients.First(x => x.Id == pc.Key), + }); context.SaveChanges(); } _visitClients = null;