From 33d22bbb246cf6f5f419b23837fe6821ec94a49a Mon Sep 17 00:00:00 2001 From: maxnes3 <112558334+maxnes3@users.noreply.github.com> Date: Sat, 20 May 2023 11:00:13 +0400 Subject: [PATCH] fix update lawyer --- .../Controllers/Lawyers.cs | 7 +++++ .../wwwroot/js/Lawyers/lawyer-update.js | 26 +++++++++++-------- .../wwwroot/js/Report/reportlist.js | 2 +- .../Models/Lawyer.cs | 7 +++++ .../Views/Shared/_Layout.cshtml | 2 +- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs index 1f0e19c..ba8c8bd 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/Lawyers.cs @@ -61,6 +61,13 @@ namespace CaseAccountingCustomerView.Controllers dict.Add(element.Id, _case); } lawyerModel.Cases = dict; + var dictContr = new Dictionary(); + foreach (var element in lawyerModel.ContractViewModels) + { + var contract = APIUser.GetRequest($"api/contract/get?id={element.Id}"); + dictContr.Add(element.Id, contract); + } + lawyerModel.Contracts = dictContr; APIUser.PostRequest("api/lawyer/update", lawyerModel); Response.Redirect("/Home/Lawyers"); } diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js index 1c3a921..a0c0cc2 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Lawyers/lawyer-update.js @@ -1,7 +1,9 @@ const createBtn = document.getElementById("create-button"); const tbody = document.getElementById("scrollable-table__tbody"); -const serviceInput = document.getElementById("service-input"); -const coastInput = document.getElementById("coast-input"); +const nameInput = document.getElementById("name-input") +const surnameInput = document.getElementById("surname-input") +const patronymicInput = document.getElementById("patronymic-input") +const experienceInput = document.getElementById("experience-input") const currentLawyerId = document.getElementById("lawyer-id").dataset.id; var contracts = []; var dataArray = []; @@ -17,7 +19,7 @@ window.addEventListener('load', async () => { }); console.log(currentLawyerId) await $.ajax({ - url: "/lawyers/get?id=${currentLawyerId}", + url: `/lawyers/get?id=${currentLawyerId}`, type: "GET", contentType: "json" }).done((result) => { @@ -36,23 +38,25 @@ window.addEventListener('load', async () => { cell.textContent = value; }); console.log(currentLawyer); - if (currentLawyer.ContractViewModels.find(x => parseInt(x.id) === parseInt(contract.id))) { + /*if (currentLawyer.сontractViewModels.find(x => parseInt(x.id) === parseInt(contract.id))) { row.classList.add("bg-success"); dataArray.push(contract); - } + }*/ row.addEventListener('click', () => addAndRemoveFromList(row)); }); }) createBtn.addEventListener('click', () => { + console.log(dataArray); var lawyerCasesUpdate = { - "Id": currentLawyer.id, - "Service": serviceInput.value, - "Coast": coastInput.value, - "Date": currentLawyer.date, - "ContractViewModels": dataArray, - "LawyerCases": currentLawyer.lawyerCases, + "Id": currentLawyerId, + "Name": nameInput.value, + "Surname": surnameInput.value, + "Patronymic": patronymicInput.value, + "Experience": parseInt(experienceInput.value), + "SpecializationId": parseInt(currentLawyer.specializationId), + "ContractViewModels": dataArray } $.ajax({ url: "/lawyers/update", diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js index fe47bc2..b775f3a 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js @@ -66,7 +66,7 @@ const createRowForLawyersTable = (lawyer) => { const row = tbody.insertRow(); row.setAttribute("data-id", id); - const cells = [name, surname, patronymic, experience, specialization]; + const cells = [name, surname, patronymic, experience, specialization ]; cells.forEach((value) => { const cell = row.insertCell(); cell.textContent = value; diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs index fd7359f..a19305c 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs @@ -114,6 +114,13 @@ namespace CaseAccountingDataBaseImplement.Models Case = context.Cases.First(y => y.Id == x.Key) }).ToList(); } + if (model.Contracts.Count > 0) + { + LawyerContracts = model.Contracts.Select(x => new LawyerContract + { + Contract = context.Contracts.First(y => y.Id == x.Key) + }).ToList(); + } } public void UpdateContracts(CaseAccountingDatabase context, LawyerBindingModel model) diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index e3fdc9e..f759a54 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -12,7 +12,7 @@