fix update lawyer

This commit is contained in:
maxnes3 2023-05-20 11:00:13 +04:00
parent 2cca5bd9b9
commit 33d22bbb24
5 changed files with 31 additions and 13 deletions

View File

@ -61,6 +61,13 @@ namespace CaseAccountingCustomerView.Controllers
dict.Add(element.Id, _case); dict.Add(element.Id, _case);
} }
lawyerModel.Cases = dict; lawyerModel.Cases = dict;
var dictContr = new Dictionary<int, IContractModel>();
foreach (var element in lawyerModel.ContractViewModels)
{
var contract = APIUser.GetRequest<ContractViewModel>($"api/contract/get?id={element.Id}");
dictContr.Add(element.Id, contract);
}
lawyerModel.Contracts = dictContr;
APIUser.PostRequest("api/lawyer/update", lawyerModel); APIUser.PostRequest("api/lawyer/update", lawyerModel);
Response.Redirect("/Home/Lawyers"); Response.Redirect("/Home/Lawyers");
} }

View File

@ -1,7 +1,9 @@
const createBtn = document.getElementById("create-button"); const createBtn = document.getElementById("create-button");
const tbody = document.getElementById("scrollable-table__tbody"); const tbody = document.getElementById("scrollable-table__tbody");
const serviceInput = document.getElementById("service-input"); const nameInput = document.getElementById("name-input")
const coastInput = document.getElementById("coast-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; const currentLawyerId = document.getElementById("lawyer-id").dataset.id;
var contracts = []; var contracts = [];
var dataArray = []; var dataArray = [];
@ -17,7 +19,7 @@ window.addEventListener('load', async () => {
}); });
console.log(currentLawyerId) console.log(currentLawyerId)
await $.ajax({ await $.ajax({
url: "/lawyers/get?id=${currentLawyerId}", url: `/lawyers/get?id=${currentLawyerId}`,
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}).done((result) => { }).done((result) => {
@ -36,23 +38,25 @@ window.addEventListener('load', async () => {
cell.textContent = value; cell.textContent = value;
}); });
console.log(currentLawyer); 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"); row.classList.add("bg-success");
dataArray.push(contract); dataArray.push(contract);
} }*/
row.addEventListener('click', () => addAndRemoveFromList(row)); row.addEventListener('click', () => addAndRemoveFromList(row));
}); });
}) })
createBtn.addEventListener('click', () => { createBtn.addEventListener('click', () => {
console.log(dataArray);
var lawyerCasesUpdate = { var lawyerCasesUpdate = {
"Id": currentLawyer.id, "Id": currentLawyerId,
"Service": serviceInput.value, "Name": nameInput.value,
"Coast": coastInput.value, "Surname": surnameInput.value,
"Date": currentLawyer.date, "Patronymic": patronymicInput.value,
"ContractViewModels": dataArray, "Experience": parseInt(experienceInput.value),
"LawyerCases": currentLawyer.lawyerCases, "SpecializationId": parseInt(currentLawyer.specializationId),
"ContractViewModels": dataArray
} }
$.ajax({ $.ajax({
url: "/lawyers/update", url: "/lawyers/update",

View File

@ -114,6 +114,13 @@ namespace CaseAccountingDataBaseImplement.Models
Case = context.Cases.First(y => y.Id == x.Key) Case = context.Cases.First(y => y.Id == x.Key)
}).ToList(); }).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) public void UpdateContracts(CaseAccountingDatabase context, LawyerBindingModel model)

View File

@ -12,7 +12,7 @@
<header> <header>
<nav class="navbar navbar-expand-lg bg-body-tertiary bg-primary" data-bs-theme="dark"> <nav class="navbar navbar-expand-lg bg-body-tertiary bg-primary" data-bs-theme="dark">
<div class="container"> <div class="container">
<a class="navbar-brand text-white" asp-area="" asp-controller="Home" aspaction="Index">Юридическая фирма "Вас обманут"</a> <a class="navbar-brand text-white" asp-area="" asp-controller="Home" asp-action="Index">Юридическая фирма "Вас обманут"</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>