diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs index f881a17..c89699b 100644 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs @@ -26,6 +26,10 @@ namespace CaseAccountingContracts.BindingModels public int Id { get; set; } + public Dictionary Cases { get; set; } = new(); + + public List CaseViewModels { get; set; } = new(); + public Dictionary Contracts { get; set; } = new(); public List ContractViewModels { get; set; } = new(); @@ -33,9 +37,10 @@ namespace CaseAccountingContracts.BindingModels public LawyerBindingModel() { } [JsonConstructor] - public LawyerBindingModel(Dictionary Contracts) + public LawyerBindingModel(Dictionary Contracts, Dictionary Cases) { this.Contracts = Contracts.ToDictionary(x => x.Key, x => (IContractModel)x.Value); + this.Cases = Cases.ToDictionary(x => x.Key, x => (ICaseModel)x.Value); } } diff --git a/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs b/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs index df0d236..ace9498 100644 --- a/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs +++ b/CaseAccounting/CaseAccountingContracts/ViewModels/LawyerViewModel.cs @@ -24,5 +24,7 @@ namespace CaseAccountingContracts.ViewModels public int UserId { get; set; } public int Id { get; set; } public Dictionary Contracts { get; set; } = new(); + + public Dictionary Cases { get; set; } = new(); } } diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs index 1362c3e..1f0e19c 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs @@ -54,6 +54,13 @@ namespace CaseAccountingCustomerView.Controllers throw new Exception("403"); } lawyerModel.UserId = APIUser.User.Id; + var dict = new Dictionary(); + foreach (var element in lawyerModel.CaseViewModels) + { + var _case = APIUser.GetRequest($"api/case/get?id={element.Id}"); + dict.Add(element.Id, _case); + } + lawyerModel.Cases = dict; APIUser.PostRequest("api/lawyer/update", lawyerModel); Response.Redirect("/Home/Lawyers"); } @@ -99,6 +106,16 @@ namespace CaseAccountingCustomerView.Controllers return View(); } + [HttpPost] + public void Bind([FromBody] LawyerBindingModel lawyerModel) + { + if (APIUser.User == null) + { + throw new Exception("403"); + } + APIUser.PostRequest("api/lawyer/update", lawyerModel); + } + public List GetAllByUserAndSpecialization(int specialization) { if (APIUser.User == null) diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml index e508a2d..1df8103 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml @@ -51,6 +51,9 @@ @item.Specialization + + Привязка + Изменить diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js index b76e970..132ccc8 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js @@ -8,7 +8,7 @@ var currentLawyer = null; window.addEventListener('load', async () => { await $.ajax({ - url: "/lawyer/getallcases", + url: "/lawyers/getallcases", type: "GET", contentType: "json" }).done((result) => { @@ -16,28 +16,32 @@ window.addEventListener('load', async () => { console.log(cases) }); await $.ajax({ - url: `/lawyer/get?id=${currentLawyerId}`, + url: `/lawyers/get?id=${currentLawyerId}`, type: "GET", contentType: "json" }).done((result) => { currentLawyer = result; - console.log(currentLawyer) }); - groups.forEach((case) => createRowForCasesTable(case)); + cases.forEach((_case) => createRowForCasesTable(_case)); }) createBtn.addEventListener('click', () => { + console.log("My data:") + console.log(currentLawyer); + console.log(dataArray); var lawyerCasesUpdate = { "Id": currentLawyer.id, "Name": currentLawyer.name, - "Surname": currentLawyer.Surname, - "Patronymic": currentLawyer.Patronymic, - "SpecializationId": currentLawyer.SpecializationId, - "ContractViewModels": currentLawyer.lawyerContracts, - "LawyerCases": dataArray, + "Surname": currentLawyer.surname, + "Patronymic": currentLawyer.patronymic, + "SpecializationId": currentLawyer.specializationId, + "Experience": currentLawyer.experience, + "ContractViewModels": currentLawyer.contractViewModels, + "CaseViewModels": dataArray, } + console.log(lawyerCasesUpdate); $.ajax({ - url: "/lawyer/update", + url: "/lawyers/update", type: "POST", contentType: "application/json", data: JSON.stringify(lawyerCasesUpdate) @@ -46,8 +50,8 @@ createBtn.addEventListener('click', () => { }); }) -const createRowForCasesTable = (case) => { - const { id, name, applicant, defendant, annotation, date, specializationId } = case; +const createRowForCasesTable = (_case) => { + const { id, name, applicant, defendant, annotation, date, specializationId } = _case; const row = tbody.insertRow(); row.setAttribute("data-id", id); @@ -57,9 +61,9 @@ const createRowForCasesTable = (case) => { cell.textContent = value; }); console.log(currentLawyer) - if (currentLawyer.lawyerCases?.find(x => parseInt(x.id) === parseInt(case.id))) { + if (currentLawyer.lawyerCases?.find(x => parseInt(x.id) === parseInt(_case.id))) { row.classList.add("bg-success"); - dataArray.push(case); + dataArray.push(_case); } row.addEventListener('click', () => addAndRemoveFromList(row)); diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs index 6d499fe..43f37c4 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/LawyerStorage.cs @@ -123,9 +123,12 @@ namespace CaseAccountingDataBaseImplement.Implements { return null; } - lawyer.Update(model); + lawyer.Update(context, model); context.SaveChanges(); - lawyer.UpdateContracts(context, model); + if (model.Cases.Count > 0) + { + lawyer.UpdateContracts(context, model); + } transaction.Commit(); return lawyer.GetViewModel; } diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519162440_migrBindTry1.Designer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519162440_migrBindTry1.Designer.cs new file mode 100644 index 0000000..b5d9446 --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519162440_migrBindTry1.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("20230519162440_migrBindTry1")] + partial class migrBindTry1 + { + /// + 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/20230519162440_migrBindTry1.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519162440_migrBindTry1.cs new file mode 100644 index 0000000..002bf73 --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519162440_migrBindTry1.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CaseAccountingDataBaseImplement.Migrations +{ + /// + public partial class migrBindTry1 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519172138_migrBindTry2.Designer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519172138_migrBindTry2.Designer.cs new file mode 100644 index 0000000..218a191 --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519172138_migrBindTry2.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("20230519172138_migrBindTry2")] + partial class migrBindTry2 + { + /// + 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/20230519172138_migrBindTry2.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519172138_migrBindTry2.cs new file mode 100644 index 0000000..5a3ff3d --- /dev/null +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519172138_migrBindTry2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace CaseAccountingDataBaseImplement.Migrations +{ + /// + public partial class migrBindTry2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs index a1f88cf..fd7359f 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs @@ -96,7 +96,7 @@ namespace CaseAccountingDataBaseImplement.Models }; } - public void Update(LawyerBindingModel? model) + public void Update(CaseAccountingDatabase context, LawyerBindingModel? model) { if (model == null) { @@ -107,6 +107,13 @@ namespace CaseAccountingDataBaseImplement.Models Patronymic = model.Patronymic; Experience = model.Experience; SpecializationId = model.SpecializationId; + if (model.Cases.Count > 0) + { + CaseLawyers = model.Cases.Select(x => new CaseLawyer + { + Case = context.Cases.First(y => y.Id == x.Key) + }).ToList(); + } } public void UpdateContracts(CaseAccountingDatabase context, LawyerBindingModel model) @@ -141,6 +148,38 @@ namespace CaseAccountingDataBaseImplement.Models } } + public void UpdateCases(CaseAccountingDatabase context, LawyerBindingModel model) + { + var lawyerCases = context.CaseLawyers + .Where(x => x.LawyerId == model.Id) + .ToList(); + if (lawyerCases != null) + { + context.CaseLawyers + .RemoveRange(lawyerCases + .Where(x => !model.Cases + .ContainsKey(x.CaseId)) + ); + context.SaveChanges(); + var lawyer = context.Lawyers + .First(x => x.Id == Id); + foreach (var lc in lawyerCases) + { + model.Cases.Remove(lc.CaseId); + } + foreach (var lc in model.Cases) + { + context.CaseLawyers.Add(new CaseLawyer + { + Lawyer = lawyer, + Case = context.Cases.First(x => x.Id == lc.Key), + }); + context.SaveChanges(); + } + _contracts = null; + } + } + public LawyerViewModel GetViewModel => new() { Id = Id, diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs index 263d94a..8c1f18b 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs @@ -86,7 +86,7 @@ namespace CaseAccountingRestApi.Controllers } [HttpGet] - public List? GetAllGroups() + public List? GetAllCases() { try {