From cd661669c0bc665ec071c06a81ade21d305df90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Fri, 19 May 2023 20:02:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=8E=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D1=82=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/LawyerBindingModel.cs | 10 +- .../ViewModels/LawyerViewModel.cs | 2 +- .../Controllers/Lawyers.cs | 10 +- .../Views/Home/Lawyers.cshtml | 4 +- .../Views/Specializations/AddLawyer.cshtml | 2 +- .../specializations-add-lawyer.js | 1 + .../CaseAccountingDatabase.cs | 4 +- ...9143905_migrSpecializationNull.Designer.cs | 554 ++++++++++++++++++ .../20230519143905_migrSpecializationNull.cs | 22 + ...migrSpecializationNullAttempt2.Designer.cs | 551 +++++++++++++++++ ...19145356_migrSpecializationNullAttempt2.cs | 59 ++ .../CaseAccountingDatabaseModelSnapshot.cs | 6 +- .../Models/Lawyer.cs | 32 +- .../Models/ILawyerModel.cs | 2 +- 14 files changed, 1240 insertions(+), 19 deletions(-) create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.Designer.cs create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.cs create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.Designer.cs create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.cs diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs index 89e0e94..f881a17 100644 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs @@ -1,5 +1,6 @@ using CaseAccountingContracts.ViewModels; using CaseAccountingDataModels.Models; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; @@ -19,7 +20,7 @@ namespace CaseAccountingContracts.BindingModels public int Experience { get; set; } - public int SpecializationId { get; set; } + public int? SpecializationId { get; set; } public int UserId { get; set; } @@ -29,6 +30,13 @@ namespace CaseAccountingContracts.BindingModels public List ContractViewModels { get; set; } = new(); + public LawyerBindingModel() { } + + [JsonConstructor] + public LawyerBindingModel(Dictionary Contracts) + { + this.Contracts = Contracts.ToDictionary(x => x.Key, x => (IContractModel)x.Value); + } } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs index 35f6781..df0d236 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs @@ -18,7 +18,7 @@ namespace CaseAccountingContracts.ViewModels public string Patronymic { get; set; } = string.Empty; [DisplayName("Опыт работы")] public int Experience { get; set; } - public int SpecializationId { get; set; } + public int? SpecializationId { get; set; } [DisplayName("Специализация")] public string Specialization { get; set; } = string.Empty; public int UserId { get; set; } diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs index 6526b85..1362c3e 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs @@ -1,5 +1,6 @@ using CaseAccountingContracts.BindingModels; using CaseAccountingContracts.ViewModels; +using CaseAccountingDataModels.Models; using Microsoft.AspNetCore.Mvc; namespace CaseAccountingCustomerView.Controllers @@ -23,7 +24,14 @@ namespace CaseAccountingCustomerView.Controllers throw new Exception("403"); } lawyerModel.UserId = APIUser.User.Id; - lawyerModel.SpecializationId = 0; + lawyerModel.SpecializationId = null; + var dict = new Dictionary(); + foreach (var element in lawyerModel.ContractViewModels) + { + var contract = APIUser.GetRequest($"api/contract/get?id={element.Id}"); + dict.Add(element.Id, contract); + } + lawyerModel.Contracts = dict; APIUser.PostRequest("api/lawyer/create", lawyerModel); Response.Redirect("/Home/Lawyers"); } diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml index cfbaba5..e508a2d 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml @@ -49,10 +49,10 @@ @item.Experience - @item.SpecializationName + @item.Specialization - Изменить + Изменить Удалить diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Specializations/AddLawyer.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Specializations/AddLawyer.cshtml index 1965f6b..60ac8f0 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Specializations/AddLawyer.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Specializations/AddLawyer.cshtml @@ -54,4 +54,4 @@ } - \ No newline at end of file + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specializations-add-lawyer.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specializations-add-lawyer.js index 5db763e..d6ee26e 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specializations-add-lawyer.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Specializations/specializations-add-lawyer.js @@ -16,6 +16,7 @@ window.addEventListener("load", async () => { }); lawyers = lawyersResponse; + console.log(lawyers); lawyers.forEach((lawyer) => { createLawyerOption(lawyer); }); diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs index 75477ba..55243a9 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/CaseAccountingDatabase.cs @@ -18,8 +18,8 @@ namespace CaseAccountingDataBaseImplement Host=localhost; Port=5432; Database=CaseAccountingDatabase; - Username=courseuser; - Password=courseuser"); + Username=postgres; + Password=postgres"); } base.OnConfiguring(optionsBuilder); } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.Designer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.Designer.cs new file mode 100644 index 0000000..5ba152e --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.Designer.cs @@ -0,0 +1,554 @@ +// +using System; +using CaseAccountingDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace CaseAccountingDataBaseImplement.Migrations +{ + [DbContext(typeof(CaseAccountingDatabase))] + [Migration("20230519143905_migrSpecializationNull")] + partial class migrSpecializationNull + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Case", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Defendant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpecializationId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SpecializationId"); + + b.HasIndex("UserId"); + + b.ToTable("Cases"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseDeal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("integer"); + + b.Property("DealId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("DealId"); + + b.ToTable("CaseDeals"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("integer"); + + b.Property("LawyerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("LawyerId"); + + b.ToTable("CaseLawyers"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Contract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Coast") + .HasColumnType("numeric"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Service") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Contracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Deal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Responsibilities") + .IsRequired() + .HasColumnType("text"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Deals"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.DealContract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ContractId") + .HasColumnType("integer"); + + b.Property("DealId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ContractId"); + + b.HasIndex("DealId"); + + b.ToTable("DealContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Hearing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Information") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("UserId"); + + b.ToTable("Hearings"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Lawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpecializationId") + .IsRequired() + .HasColumnType("integer"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SpecializationId"); + + b.HasIndex("UserId"); + + b.ToTable("Lawyers"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.LawyerContract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ContractId") + .HasColumnType("integer"); + + b.Property("LawyerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ContractId"); + + b.HasIndex("LawyerId"); + + b.ToTable("LawyerContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Specialization", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Specializations"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Case", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Specialization", "Specialization") + .WithMany("Cases") + .HasForeignKey("SpecializationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Cases") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Specialization"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseDeal", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Case", "Case") + .WithMany("Deals") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Deal", "Deal") + .WithMany("CaseDeals") + .HasForeignKey("DealId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("Deal"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseLawyer", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Case", "Case") + .WithMany("CaseLawyers") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Lawyer", "Lawyer") + .WithMany("CaseLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Contract", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Contracts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Deal", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Deals") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.DealContract", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Contract", "Contract") + .WithMany("DealContracts") + .HasForeignKey("ContractId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Deal", "Deal") + .WithMany("Contracts") + .HasForeignKey("DealId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contract"); + + b.Navigation("Deal"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Hearing", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Case", "Case") + .WithMany("Hearings") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Hearings") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Lawyer", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Specialization", "Specialization") + .WithMany("Lawyers") + .HasForeignKey("SpecializationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Lawyers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Specialization"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.LawyerContract", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Contract", "Contract") + .WithMany("LawyerContracts") + .HasForeignKey("ContractId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Lawyer", "Lawyer") + .WithMany("LawyerContracts") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contract"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Specialization", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Specializations") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Case", b => + { + b.Navigation("CaseLawyers"); + + b.Navigation("Deals"); + + b.Navigation("Hearings"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Contract", b => + { + b.Navigation("DealContracts"); + + b.Navigation("LawyerContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Deal", b => + { + b.Navigation("CaseDeals"); + + b.Navigation("Contracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Lawyer", b => + { + b.Navigation("CaseLawyers"); + + b.Navigation("LawyerContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Specialization", b => + { + b.Navigation("Cases"); + + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.User", b => + { + b.Navigation("Cases"); + + b.Navigation("Contracts"); + + b.Navigation("Deals"); + + b.Navigation("Hearings"); + + b.Navigation("Lawyers"); + + b.Navigation("Specializations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.cs new file mode 100644 index 0000000..3985bb8 --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519143905_migrSpecializationNull.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CaseAccountingDataBaseImplement.Migrations +{ + /// + public partial class migrSpecializationNull : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.Designer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.Designer.cs new file mode 100644 index 0000000..6176a40 --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.Designer.cs @@ -0,0 +1,551 @@ +// +using System; +using CaseAccountingDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace CaseAccountingDataBaseImplement.Migrations +{ + [DbContext(typeof(CaseAccountingDatabase))] + [Migration("20230519145356_migrSpecializationNullAttempt2")] + partial class migrSpecializationNullAttempt2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Case", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Annotation") + .IsRequired() + .HasColumnType("text"); + + b.Property("Applicant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Defendant") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpecializationId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SpecializationId"); + + b.HasIndex("UserId"); + + b.ToTable("Cases"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseDeal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("integer"); + + b.Property("DealId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("DealId"); + + b.ToTable("CaseDeals"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseLawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("integer"); + + b.Property("LawyerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("LawyerId"); + + b.ToTable("CaseLawyers"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Contract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Coast") + .HasColumnType("numeric"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Service") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Contracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Deal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Responsibilities") + .IsRequired() + .HasColumnType("text"); + + b.Property("Subject") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Deals"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.DealContract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ContractId") + .HasColumnType("integer"); + + b.Property("DealId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ContractId"); + + b.HasIndex("DealId"); + + b.ToTable("DealContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Hearing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CaseId") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Information") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CaseId"); + + b.HasIndex("UserId"); + + b.ToTable("Hearings"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Lawyer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.Property("SpecializationId") + .HasColumnType("integer"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("SpecializationId"); + + b.HasIndex("UserId"); + + b.ToTable("Lawyers"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.LawyerContract", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ContractId") + .HasColumnType("integer"); + + b.Property("LawyerId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ContractId"); + + b.HasIndex("LawyerId"); + + b.ToTable("LawyerContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Specialization", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Specializations"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Case", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Specialization", "Specialization") + .WithMany("Cases") + .HasForeignKey("SpecializationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Cases") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Specialization"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseDeal", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Case", "Case") + .WithMany("Deals") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Deal", "Deal") + .WithMany("CaseDeals") + .HasForeignKey("DealId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("Deal"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseLawyer", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Case", "Case") + .WithMany("CaseLawyers") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Lawyer", "Lawyer") + .WithMany("CaseLawyers") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Contract", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Contracts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Deal", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Deals") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.DealContract", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Contract", "Contract") + .WithMany("DealContracts") + .HasForeignKey("ContractId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Deal", "Deal") + .WithMany("Contracts") + .HasForeignKey("DealId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contract"); + + b.Navigation("Deal"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Hearing", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Case", "Case") + .WithMany("Hearings") + .HasForeignKey("CaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Hearings") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Case"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Lawyer", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Specialization", "Specialization") + .WithMany("Lawyers") + .HasForeignKey("SpecializationId"); + + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Lawyers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Specialization"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.LawyerContract", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.Contract", "Contract") + .WithMany("LawyerContracts") + .HasForeignKey("ContractId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("CaseAccountingDataBaseImplement.Models.Lawyer", "Lawyer") + .WithMany("LawyerContracts") + .HasForeignKey("LawyerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contract"); + + b.Navigation("Lawyer"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Specialization", b => + { + b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") + .WithMany("Specializations") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Case", b => + { + b.Navigation("CaseLawyers"); + + b.Navigation("Deals"); + + b.Navigation("Hearings"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Contract", b => + { + b.Navigation("DealContracts"); + + b.Navigation("LawyerContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Deal", b => + { + b.Navigation("CaseDeals"); + + b.Navigation("Contracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Lawyer", b => + { + b.Navigation("CaseLawyers"); + + b.Navigation("LawyerContracts"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Specialization", b => + { + b.Navigation("Cases"); + + b.Navigation("Lawyers"); + }); + + modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.User", b => + { + b.Navigation("Cases"); + + b.Navigation("Contracts"); + + b.Navigation("Deals"); + + b.Navigation("Hearings"); + + b.Navigation("Lawyers"); + + b.Navigation("Specializations"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.cs new file mode 100644 index 0000000..6840ab6 --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519145356_migrSpecializationNullAttempt2.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CaseAccountingDataBaseImplement.Migrations +{ + /// + public partial class migrSpecializationNullAttempt2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Lawyers_Specializations_SpecializationId", + table: "Lawyers"); + + migrationBuilder.AlterColumn( + name: "SpecializationId", + table: "Lawyers", + type: "integer", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AddForeignKey( + name: "FK_Lawyers_Specializations_SpecializationId", + table: "Lawyers", + column: "SpecializationId", + principalTable: "Specializations", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Lawyers_Specializations_SpecializationId", + table: "Lawyers"); + + migrationBuilder.AlterColumn( + name: "SpecializationId", + table: "Lawyers", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Lawyers_Specializations_SpecializationId", + table: "Lawyers", + column: "SpecializationId", + principalTable: "Specializations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/CaseAccountingDatabaseModelSnapshot.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/CaseAccountingDatabaseModelSnapshot.cs index 6723299..7d4655b 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/CaseAccountingDatabaseModelSnapshot.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/CaseAccountingDatabaseModelSnapshot.cs @@ -239,7 +239,7 @@ namespace CaseAccountingDataBaseImplement.Migrations .IsRequired() .HasColumnType("text"); - b.Property("SpecializationId") + b.Property("SpecializationId") .HasColumnType("integer"); b.Property("Surname") @@ -448,9 +448,7 @@ namespace CaseAccountingDataBaseImplement.Migrations { b.HasOne("CaseAccountingDataBaseImplement.Models.Specialization", "Specialization") .WithMany("Lawyers") - .HasForeignKey("SpecializationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("SpecializationId"); b.HasOne("CaseAccountingDataBaseImplement.Models.User", "User") .WithMany("Lawyers") diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs index 820d1d0..a1f88cf 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs @@ -27,9 +27,8 @@ namespace CaseAccountingDataBaseImplement.Models [Required] public int Experience { get; set; } - [Required] - public int SpecializationId { get; set; } - public virtual Specialization Specialization { get; set; } = new(); + public int? SpecializationId { get; set; } + public virtual Specialization? Specialization { get; set; } = new(); [Required] public int UserId { get; set; } @@ -38,6 +37,22 @@ namespace CaseAccountingDataBaseImplement.Models [ForeignKey("LawyerId")] public virtual List CaseLawyers { get; set; } = new(); + private Dictionary? _cases; + + [NotMapped] + public Dictionary Cases + { + get + { + if (_cases == null) + { + _cases = CaseLawyers.ToDictionary( + x => x.CaseId, x => x.Case as ICaseModel); + } + return _cases; + } + } + [ForeignKey("LawyerId")] public virtual List LawyerContracts { get; set; } = new(); @@ -71,9 +86,13 @@ namespace CaseAccountingDataBaseImplement.Models Patronymic = model.Patronymic, Experience = model.Experience, SpecializationId = model.SpecializationId, - Specialization = context.Specializations.FirstOrDefault(x => x.Id == model.SpecializationId) ?? throw new Exception("specialization not found"), + Specialization = context.Specializations.FirstOrDefault(x => model.SpecializationId.HasValue && x.Id == model.SpecializationId), UserId = model.UserId, - User = context.Users.FirstOrDefault(x => x.Id == model.UserId) ?? throw new Exception("User not found") + User = context.Users.FirstOrDefault(x => x.Id == model.UserId) ?? throw new Exception("User not found"), + LawyerContracts = model.Contracts.Select(x => new LawyerContract + { + Contract = context.Contracts.First(y => y.Id == x.Key) + }).ToList() }; } @@ -130,7 +149,8 @@ namespace CaseAccountingDataBaseImplement.Models Patronymic = Patronymic, Experience = Experience, SpecializationId = SpecializationId, - UserId = UserId + UserId = UserId, + Specialization = Specialization?.Name ?? "Не указан" }; } } diff --git a/CaseAccounting/CaseAccountingDataModels/Models/ILawyerModel.cs b/CaseAccounting/CaseAccountingDataModels/Models/ILawyerModel.cs index 9ad9276..6086f13 100644 --- a/CaseAccounting/CaseAccountingDataModels/Models/ILawyerModel.cs +++ b/CaseAccounting/CaseAccountingDataModels/Models/ILawyerModel.cs @@ -12,7 +12,7 @@ namespace CaseAccountingDataModels.Models string Surname { get; } string Patronymic { get; } int Experience { get; } - int SpecializationId { get; } + int? SpecializationId { get; } int UserId { get; } Dictionary Contracts { get; } }