From 79071f22b2db0836edb388b6b1fbc30fce05c9a6 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 14:53:49 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=9F=D1=8B=D1=82=D0=B0=D0=B5=D0=BC=D1=81?= =?UTF-8?q?=D1=8F=20=D0=BF=D1=80=D0=B8=D0=BA=D1=80=D1=83=D1=82=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BC=D0=BD=D0=BE=D0=B3=D0=B8=D0=B5-=D0=BA=D0=BE-?= =?UTF-8?q?=D0=BC=D0=BD=D0=BE=D0=B3=D0=B8=D0=BC=20=D1=8E=D1=80=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D1=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Lawyers.cs | 12 +++++ .../Controllers/Specializations.cs | 19 +++++++ .../Views/Home/Lawyers.cshtml | 8 +-- .../Views/Home/Specializations.cshtml | 5 +- .../Views/Lawyers/Bind.cshtml | 6 +-- .../Views/Lawyers/Create.cshtml | 18 ++++++- .../Views/Lawyers/Update.cshtml | 2 +- .../Views/Specializations/AddLawyer.cshtml | 2 +- .../wwwroot/js/Lawyers/lawyer-bind.js | 50 ++++++++++--------- .../wwwroot/js/Lawyers/lawyer-create.js | 7 +-- .../wwwroot/js/Lawyers/lawyer-update.js | 8 +-- .../wwwroot/js/Lawyers/lawyers.js | 2 +- .../Controllers/LawyerController.cs | 31 +++++++++++- 13 files changed, 126 insertions(+), 44 deletions(-) diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs index 13bbee4..070493c 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs @@ -23,6 +23,7 @@ namespace CaseAccountingCustomerView.Controllers throw new Exception("403"); } lawyerModel.UserId = APIUser.User.Id; + lawyerModel.SpecializationId = 0; APIUser.PostRequest("api/lawyer/create", lawyerModel); Response.Redirect("/Home/Lawyers"); } @@ -109,6 +110,17 @@ namespace CaseAccountingCustomerView.Controllers List? lawyers = APIUser.GetRequest>($"api/lawyer/getallbyuserandspecialization?userId={APIUser.User.Id}&specialization={specialization}"); return lawyers ?? new(); } + + public List GetAllCases() + { + if (APIUser.User == null) + { + return new(); + } + List? _case = APIUser.GetRequest>("api/lawyer/GetAllCases"); + return _case ?? new(); + } + } } diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/Specializations.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/Specializations.cs index 6872185..94d10f8 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/Specializations.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/Specializations.cs @@ -79,5 +79,24 @@ namespace CaseAccountingCustomerView.Controllers SpecializationViewModel? specialization = APIUser.GetRequest($"api/specialization/get?id={id}"); return specialization; } + public IActionResult AddLawyer(int id) + { + if (APIUser.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.SpecializationId = id; + return View(); + } + + [HttpPost] + public void AddLawyer([FromBody] LawyerBindingModel lawyerModel) + { + if (APIUser.User == null) + { + throw new Exception("403"); + } + APIUser.PostRequest("api/lawyer/update", lawyerModel); + } } } diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml index 031ea96..cfbaba5 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Lawyers.cshtml @@ -16,7 +16,7 @@ return; } @@ -46,10 +46,10 @@ @item.Name @item.Surname @item.Patronymic + @@ -57,4 +60,4 @@ } - \ No newline at end of file + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Bind.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Bind.cshtml index 5ab8b45..e85b9cc 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Bind.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Bind.cshtml @@ -12,7 +12,7 @@

Название:

- +
- @item.StudentCard + @item.Experience - @item.EducationStatusName + @item.SpecializationName Изменить @@ -64,4 +64,4 @@ } - \ No newline at end of file + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Specializations.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Specializations.cshtml index 4be00f1..2ef2668 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Home/Specializations.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Home/Specializations.cshtml @@ -44,6 +44,9 @@ @item.Name + Назначить специализацию для юриста + Изменить
- + @@ -32,4 +32,4 @@ } - \ No newline at end of file + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Create.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Create.cshtml index 8157214..750deeb 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Create.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Create.cshtml @@ -19,8 +19,24 @@

Опыт работы:

+
+
+
Название группы:Название дела:
+ + + + + + + + + +
УслугаЦенаДата
+ + + - \ No newline at end of file + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Update.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Update.cshtml index 17079e3..451dceb 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Update.cshtml +++ b/CaseAccounting/CaseAccountingCustomerView/Views/Lawyers/Update.cshtml @@ -33,4 +33,4 @@ } - \ No newline at end of file + \ No newline at end of file diff --git a/CaseAccounting/CaseAccountingCustomerView/Views/Specializations/AddLawyer.cshtml b/CaseAccounting/CaseAccountingCustomerView/Views/Specializations/AddLawyer.cshtml index 7b45bed..1965f6b 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/Lawyers/lawyer-bind.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js index c51f77c..c3cd4f0 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js @@ -4,48 +4,50 @@ const nameInput = document.getElementById("name-input"); const currentLawyerId = document.getElementById("lawyer-data").dataset.id; var cases = []; var dataArray = []; -var currentlawyer = null; +var currentLawyer = null; window.addEventListener('load', async () => { await $.ajax({ - url: "/lawyer/getallgroups", + url: "/lawyer/getallcases", type: "GET", contentType: "json" }).done((result) => { - groups = result; - console.log(groups) + cases = result; + console.log(cases) }); await $.ajax({ - url: `/document/get?id=${currentDocumentId}`, + url: `/document/get?id=${currentLawyerId}`, type: "GET", contentType: "json" }).done((result) => { - currentDocument = result; - console.log(currentDocument) + currentLawyer = result; + console.log(currentLawyer) }); - groups.forEach((group) => createRowForGroupsTable(group)); + groups.forEach((case) => createRowForCasesTable(case)); }) createBtn.addEventListener('click', () => { - var documentGroupsUpdate = { - "Id": currentDocument.id, - "Name": currentDocument.name, - "Date": currentDocument.date, - "DocumentStudents": currentDocument.documentStudents, - "DocumentGroups": dataArray, + var lawyerCasesUpdate = { + "Id": currentLawyer.id, + "Name": currentLawyer.name, + "Surname": currentLawyer.Surname, + "Patronymic": currentLawyer.Patronymic, + "SpecializationId": currentLawyer.SpecializationId, + "LawyerContracts": currentLawyer.lawyerContracts, + "LawyerCases": dataArray, } $.ajax({ - url: "/document/update", + url: "/lawyer/update", type: "POST", contentType: "application/json", - data: JSON.stringify(documentGroupsUpdate) + data: JSON.stringify(lawyerCasesUpdate) }).done(() => { - window.location.href = "/Home/Documents"; + window.location.href = "/Home/Lawyers"; }); }) -const createRowForGroupsTable = (group) => { - const { id, name } = group; +const createRowForCasesTable = (case) => { + const { id, name, applicant, defendant, annotation, date, specializationId } = case; const row = tbody.insertRow(); row.setAttribute("data-id", id); @@ -54,10 +56,10 @@ const createRowForGroupsTable = (group) => { const cell = row.insertCell(); cell.textContent = value; }); - console.log(currentDocument) - if (currentDocument.documentEdGroups?.find(x => parseInt(x.id) === parseInt(group.id))) { + console.log(currentLawyer) + if (currentLawyer.lawyerCases?.find(x => parseInt(x.id) === parseInt(case.id))) { row.classList.add("bg-success"); - dataArray.push(group); + dataArray.push(case); } row.addEventListener('click', () => addAndRemoveFromList(row)); @@ -73,9 +75,9 @@ const formatDate = (dateString) => { const addAndRemoveFromList = (row) => { var id = parseInt(row.dataset.id); - var index = dataArray.indexOf(groups.find(x => x.id === id)); + var index = dataArray.indexOf(cases.find(x => x.id === id)); if (index === -1) { - dataArray.push(groups.find(x => x.id === id)); + dataArray.push(cases.find(x => x.id === id)); row.classList.add("bg-success"); } else { dataArray.splice(index, 1); diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js index d9e95c5..3dc332e 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js @@ -10,12 +10,12 @@ var dataArray = []; window.addEventListener('load', () => { $.ajax({ - url: "/contract/getallbyuser", + url: "/contracts/getallbyuser", type: "GET", contentType: "json" }).done((result) => { contracts = result; - contracts.forEach((contract) => createRowForStudentsTable(contract)); + contracts.forEach((contract) => createRowForContractsTable(contract)); }); }) @@ -27,8 +27,9 @@ createBtn.addEventListener('click', () => { "Experience": parseInt(experienceInput.value), "LawyerContracts": dataArray, } + console.log(lawyer); $.ajax({ - url: "/lawyer/create", + url: "/lawyers/create", type: "POST", contentType: "application/json", data: JSON.stringify(lawyer) diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js index 8d9a58e..4c839ab 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js @@ -9,14 +9,14 @@ var currentLawyer = null; window.addEventListener('load', async () => { await $.ajax({ - url: "/contract/getallbyuser", + url: "/contracts/getallbyuser", type: "GET", contentType: "json" }).done((result) => { contracts = result; }); await $.ajax({ - url: `/lawyer/get?id=${currentLawyerId}`, + url: `/lawyers/get?id=${currentLawyerId}`, type: "GET", contentType: "json" }).done((result) => { @@ -25,7 +25,7 @@ window.addEventListener('load', async () => { contracts.forEach((contract) => createRowForContractsTable(contract)); }) -/*createBtn.addEventListener('click', () => { +createBtn.addEventListener('click', () => { var lawyerCasesUpdate = { "Id": currentLawyer.id, "Service": serviceInput.value, @@ -42,7 +42,7 @@ window.addEventListener('load', async () => { }).done(() => { window.location.href = "/Home/Lawyers"; }); -})*/ +}) const createRowForContractsTable = (contract) => { const { id, service, coast, date} = contract; diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyers.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyers.js index 091e3c5..ae06a7d 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyers.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyers.js @@ -10,7 +10,7 @@ removeButtons.forEach(function (button) { var result = confirm("Вы уверены, что хотите удалить эту запись?"); if (result) { $.ajax({ - url: "/lawyer/delete", + url: "/lawyers/delete", type: "POST", data: { Id: id } }).done(() => { diff --git a/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs b/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs index 716033a..263d94a 100644 --- a/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs +++ b/CaseAccounting/CaseAccountingRestApi/Controllers/LawyerController.cs @@ -12,9 +12,12 @@ namespace CaseAccountingRestApi.Controllers { private readonly ILawyerLogic lawyerLogic; - public LawyerController(ILawyerLogic logic) + private readonly ICaseLogic _caseLogic; + + public LawyerController(ILawyerLogic logic, ICaseLogic caseLogic) { lawyerLogic = logic; + _caseLogic = caseLogic; } [HttpGet] @@ -81,5 +84,31 @@ namespace CaseAccountingRestApi.Controllers throw; } } + + [HttpGet] + public List? GetAllGroups() + { + try + { + return _caseLogic.ReadList(null); + } + catch (Exception ex) + { + throw; + } + } + + [HttpGet] + public List? GetAllByUserAndSpecialization(int userId, int specialization) + { + try + { + return lawyerLogic.ReadList(new LawyerSearchModel { UserId = userId, SpecializationId = specialization }); + } + catch (Exception ex) + { + throw; + } + } } } From 1843a431ecc8e22f79514a08269e462e69f5e95b 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 18:12:37 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=A7=D0=B8=D0=BD=D0=B8=D0=BC=20=D0=BC?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=B8=D0=B5-=D0=BA=D0=BE-=D0=BC=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/LawyerBindingModel.cs | 8 +++++++- .../CaseAccountingCustomerView/Controllers/Lawyers.cs | 10 ---------- .../wwwroot/js/Lawyers/lawyer-bind.js | 4 ++-- .../wwwroot/js/Lawyers/lawyer-create.js | 2 +- .../wwwroot/js/Lawyers/lawyer-update.js | 2 +- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs index d9895a1..89e0e94 100644 --- a/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs +++ b/CaseAccounting/CaseAccountingContracts/BindingModels/LawyerBindingModel.cs @@ -1,7 +1,9 @@ -using CaseAccountingDataModels.Models; +using CaseAccountingContracts.ViewModels; +using CaseAccountingDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; @@ -24,5 +26,9 @@ namespace CaseAccountingContracts.BindingModels public int Id { get; set; } public Dictionary Contracts { get; set; } = new(); + + public List ContractViewModels { get; set; } = new(); + + } } diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs index 070493c..6526b85 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs @@ -71,16 +71,6 @@ namespace CaseAccountingCustomerView.Controllers return lawyers ?? new(); } - /*public List GetAllCases() - { - if (APIUser.User == null) - { - return new(); - } - List? group = APIUser.GetRequest>("api/lawyer/GetAllCases"); - return group ?? new(); - }*/ - public LawyerViewModel? Get(int id) { if (APIUser.User == null) diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js index c3cd4f0..b76e970 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-bind.js @@ -16,7 +16,7 @@ window.addEventListener('load', async () => { console.log(cases) }); await $.ajax({ - url: `/document/get?id=${currentLawyerId}`, + url: `/lawyer/get?id=${currentLawyerId}`, type: "GET", contentType: "json" }).done((result) => { @@ -33,7 +33,7 @@ createBtn.addEventListener('click', () => { "Surname": currentLawyer.Surname, "Patronymic": currentLawyer.Patronymic, "SpecializationId": currentLawyer.SpecializationId, - "LawyerContracts": currentLawyer.lawyerContracts, + "ContractViewModels": currentLawyer.lawyerContracts, "LawyerCases": dataArray, } $.ajax({ diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js index 3dc332e..810905d 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-create.js @@ -25,7 +25,7 @@ createBtn.addEventListener('click', () => { "Surname": surnameInput.value, "Patronymic": patronymicInput.value, "Experience": parseInt(experienceInput.value), - "LawyerContracts": dataArray, + "ContractViewModels": dataArray, } console.log(lawyer); $.ajax({ diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js index 4c839ab..e773846 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js @@ -31,7 +31,7 @@ createBtn.addEventListener('click', () => { "Service": serviceInput.value, "Coast": coastInput.value, "Date": currentLawyer.date, - "LawyerContracts": dataArray, + "ContractViewModels": dataArray, "LawyerCases": currentLawyer.lawyerCases, } $.ajax({ 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 3/4] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=8E?= =?UTF-8?q?=D1=80=D0=B8=D1=81=D1=82=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=B5=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; } } From 7fcf90e006bd69a9131b8fb07909a3603d5c60b7 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 21:27:33 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9F=D0=A0=D0=98=D0=92=D0=AF=D0=97=D0=9A?= =?UTF-8?q?=D0=A3=20=D0=94=D0=9E=D0=94=D0=95=D0=9B=D0=90=D0=9B!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/LawyerBindingModel.cs | 7 +- .../ViewModels/LawyerViewModel.cs | 2 + .../Controllers/Lawyers.cs | 17 + .../Views/Home/Lawyers.cshtml | 3 + .../wwwroot/js/Lawyers/lawyer-bind.js | 32 +- .../Implements/LawyerStorage.cs | 7 +- .../20230519162440_migrBindTry1.Designer.cs | 551 ++++++++++++++++++ .../Migrations/20230519162440_migrBindTry1.cs | 22 + .../20230519172138_migrBindTry2.Designer.cs | 551 ++++++++++++++++++ .../Migrations/20230519172138_migrBindTry2.cs | 22 + .../Models/Lawyer.cs | 41 +- .../Controllers/LawyerController.cs | 2 +- 12 files changed, 1238 insertions(+), 19 deletions(-) create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519162440_migrBindTry1.Designer.cs create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519162440_migrBindTry1.cs create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519172138_migrBindTry2.Designer.cs create mode 100644 CaseAccounting/CaseAccountingDataBaseImplement/Migrations/20230519172138_migrBindTry2.cs 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 {