Пытаемся прикрутить многие-ко-многим юристы.

This commit is contained in:
Артём Алейкин 2023-05-19 14:53:49 +04:00
parent 4bea770d99
commit 79071f22b2
13 changed files with 126 additions and 44 deletions

View File

@ -23,6 +23,7 @@ namespace CaseAccountingCustomerView.Controllers
throw new Exception("403"); throw new Exception("403");
} }
lawyerModel.UserId = APIUser.User.Id; lawyerModel.UserId = APIUser.User.Id;
lawyerModel.SpecializationId = 0;
APIUser.PostRequest("api/lawyer/create", lawyerModel); APIUser.PostRequest("api/lawyer/create", lawyerModel);
Response.Redirect("/Home/Lawyers"); Response.Redirect("/Home/Lawyers");
} }
@ -109,6 +110,17 @@ namespace CaseAccountingCustomerView.Controllers
List<LawyerViewModel>? lawyers = APIUser.GetRequest<List<LawyerViewModel>>($"api/lawyer/getallbyuserandspecialization?userId={APIUser.User.Id}&specialization={specialization}"); List<LawyerViewModel>? lawyers = APIUser.GetRequest<List<LawyerViewModel>>($"api/lawyer/getallbyuserandspecialization?userId={APIUser.User.Id}&specialization={specialization}");
return lawyers ?? new(); return lawyers ?? new();
} }
public List<CaseViewModel> GetAllCases()
{
if (APIUser.User == null)
{
return new();
}
List<CaseViewModel>? _case = APIUser.GetRequest<List<CaseViewModel>>("api/lawyer/GetAllCases");
return _case ?? new();
}
} }
} }

View File

@ -79,5 +79,24 @@ namespace CaseAccountingCustomerView.Controllers
SpecializationViewModel? specialization = APIUser.GetRequest<SpecializationViewModel>($"api/specialization/get?id={id}"); SpecializationViewModel? specialization = APIUser.GetRequest<SpecializationViewModel>($"api/specialization/get?id={id}");
return specialization; 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);
}
} }
} }

View File

@ -16,7 +16,7 @@
return; return;
} }
<div> <div>
<a class="btn btn-secondary" asp-controller="Lawyer" asp-action="Create">Добавить юриста</a> <a class="btn btn-secondary" asp-controller="Lawyers" asp-action="Create">Добавить юриста</a>
</div> </div>
<table class="table"> <table class="table">
<thead> <thead>
@ -46,10 +46,10 @@
@item.Name @item.Surname @item.Patronymic @item.Name @item.Surname @item.Patronymic
</td> </td>
<td> <td>
@item.StudentCard @item.Experience
</td> </td>
<td> <td>
@item.EducationStatusName @item.SpecializationName
</td> </td>
<td> <td>
<a id="update-button-@item.Id" class="btn btn-secondary" asp-controller="Lawyer" asp-action="Update" asp-route-id="@item.Id">Изменить</a> <a id="update-button-@item.Id" class="btn btn-secondary" asp-controller="Lawyer" asp-action="Update" asp-route-id="@item.Id">Изменить</a>
@ -64,4 +64,4 @@
} }
</div> </div>
<script src="~/js/lawyer/lawyers.js" asp-append-version="true"></script> <script src="~/js/Lawyers/lawyers.js" asp-append-version="true"></script>

View File

@ -44,6 +44,9 @@
<td> <td>
@item.Name @item.Name
</td> </td>
<td>
<a id="add-lawyer-button-@item.Id" class="btn btn-secondary" asp-controller="Specializations" asp-action="AddLawyer" asp-route-id="@item.Id">Назначить специализацию для юриста</a>
</td>
<td> <td>
<a id="update-button-@item.Id" class="btn btn-secondary" asp-controller="Specialization" asp-action="Update" asp-route-id="@item.Id">Изменить</a> <a id="update-button-@item.Id" class="btn btn-secondary" asp-controller="Specialization" asp-action="Update" asp-route-id="@item.Id">Изменить</a>
</td> </td>
@ -57,4 +60,4 @@
} }
</div> </div>
<script src="~/js/specialization/specializations.js" asp-append-version="true"></script> <script src="~/js/Specializations/specializations.js" asp-append-version="true"></script>

View File

@ -12,7 +12,7 @@
</div> </div>
<p class="mb-0">Название:</p> <p class="mb-0">Название:</p>
<input type="text" readonly value="@ViewBag.Document.Name" id="name-input" name="name" class="form-control mb-3" /> <input type="text" readonly value="@ViewBag.Lawyer.Name" id="name-input" name="name" class="form-control mb-3" />
<button id="create-button" type="button" class="button-primary text-button"> <button id="create-button" type="button" class="button-primary text-button">
Сохранить привязку Сохранить привязку
@ -23,7 +23,7 @@
<table class="table table-bordered"> <table class="table table-bordered">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
<th>Название группы:</th> <th>Название дела:</th>
</tr> </tr>
</thead> </thead>
<tbody id="scrollable-table__tbody"> <tbody id="scrollable-table__tbody">
@ -32,4 +32,4 @@
</div> </div>
</div> </div>
} }
<script src="~/js/document/document-bind.js" asp-append-version="true"></script> <script src="~/js/Lawyers/lawyer-bind.js" asp-append-version="true"></script>

View File

@ -19,8 +19,24 @@
<p class="mb-0">Опыт работы:</p> <p class="mb-0">Опыт работы:</p>
<input type="number" id="experience-input" name="experience" class="form-control mb-3" /> <input type="number" id="experience-input" name="experience" class="form-control mb-3" />
<div>
<div class="scrollable-table">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Услуга</th>
<th>Цена</th>
<th>Дата</th>
</tr>
</thead>
<tbody id="scrollable-table__tbody">
</tbody>
</table>
</div>
</div>
<button id="create-button" type="button" class="button-primary text-button"> <button id="create-button" type="button" class="button-primary text-button">
Создать Создать
</button> </button>
<script src="~/js/lawyer/lawyer-create.js" asp-append-version="true"></script> <script src="~/js/Lawyers/lawyer-create.js" asp-append-version="true"></script>

View File

@ -33,4 +33,4 @@
</button> </button>
} }
<script src="~/js/lawyer/lawyer-update.js" asp-append-version="true"></script> <script src="~/js/Lawyers/lawyer-update.js" asp-append-version="true"></script>

View File

@ -54,4 +54,4 @@
</div> </div>
} }
<script src="~/js/Specializations/specialization-add-student.js" asp-append-version="true"></script> <script src="~/js/Specializations/specialization-add-lawyer.js" asp-append-version="true"></script>

View File

@ -4,48 +4,50 @@ const nameInput = document.getElementById("name-input");
const currentLawyerId = document.getElementById("lawyer-data").dataset.id; const currentLawyerId = document.getElementById("lawyer-data").dataset.id;
var cases = []; var cases = [];
var dataArray = []; var dataArray = [];
var currentlawyer = null; var currentLawyer = null;
window.addEventListener('load', async () => { window.addEventListener('load', async () => {
await $.ajax({ await $.ajax({
url: "/lawyer/getallgroups", url: "/lawyer/getallcases",
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}).done((result) => { }).done((result) => {
groups = result; cases = result;
console.log(groups) console.log(cases)
}); });
await $.ajax({ await $.ajax({
url: `/document/get?id=${currentDocumentId}`, url: `/document/get?id=${currentLawyerId}`,
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}).done((result) => { }).done((result) => {
currentDocument = result; currentLawyer = result;
console.log(currentDocument) console.log(currentLawyer)
}); });
groups.forEach((group) => createRowForGroupsTable(group)); groups.forEach((case) => createRowForCasesTable(case));
}) })
createBtn.addEventListener('click', () => { createBtn.addEventListener('click', () => {
var documentGroupsUpdate = { var lawyerCasesUpdate = {
"Id": currentDocument.id, "Id": currentLawyer.id,
"Name": currentDocument.name, "Name": currentLawyer.name,
"Date": currentDocument.date, "Surname": currentLawyer.Surname,
"DocumentStudents": currentDocument.documentStudents, "Patronymic": currentLawyer.Patronymic,
"DocumentGroups": dataArray, "SpecializationId": currentLawyer.SpecializationId,
"LawyerContracts": currentLawyer.lawyerContracts,
"LawyerCases": dataArray,
} }
$.ajax({ $.ajax({
url: "/document/update", url: "/lawyer/update",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(documentGroupsUpdate) data: JSON.stringify(lawyerCasesUpdate)
}).done(() => { }).done(() => {
window.location.href = "/Home/Documents"; window.location.href = "/Home/Lawyers";
}); });
}) })
const createRowForGroupsTable = (group) => { const createRowForCasesTable = (case) => {
const { id, name } = group; const { id, name, applicant, defendant, annotation, date, specializationId } = case;
const row = tbody.insertRow(); const row = tbody.insertRow();
row.setAttribute("data-id", id); row.setAttribute("data-id", id);
@ -54,10 +56,10 @@ const createRowForGroupsTable = (group) => {
const cell = row.insertCell(); const cell = row.insertCell();
cell.textContent = value; cell.textContent = value;
}); });
console.log(currentDocument) console.log(currentLawyer)
if (currentDocument.documentEdGroups?.find(x => parseInt(x.id) === parseInt(group.id))) { if (currentLawyer.lawyerCases?.find(x => parseInt(x.id) === parseInt(case.id))) {
row.classList.add("bg-success"); row.classList.add("bg-success");
dataArray.push(group); dataArray.push(case);
} }
row.addEventListener('click', () => addAndRemoveFromList(row)); row.addEventListener('click', () => addAndRemoveFromList(row));
@ -73,9 +75,9 @@ const formatDate = (dateString) => {
const addAndRemoveFromList = (row) => { const addAndRemoveFromList = (row) => {
var id = parseInt(row.dataset.id); 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) { if (index === -1) {
dataArray.push(groups.find(x => x.id === id)); dataArray.push(cases.find(x => x.id === id));
row.classList.add("bg-success"); row.classList.add("bg-success");
} else { } else {
dataArray.splice(index, 1); dataArray.splice(index, 1);

View File

@ -10,12 +10,12 @@ var dataArray = [];
window.addEventListener('load', () => { window.addEventListener('load', () => {
$.ajax({ $.ajax({
url: "/contract/getallbyuser", url: "/contracts/getallbyuser",
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}).done((result) => { }).done((result) => {
contracts = result; contracts = result;
contracts.forEach((contract) => createRowForStudentsTable(contract)); contracts.forEach((contract) => createRowForContractsTable(contract));
}); });
}) })
@ -27,8 +27,9 @@ createBtn.addEventListener('click', () => {
"Experience": parseInt(experienceInput.value), "Experience": parseInt(experienceInput.value),
"LawyerContracts": dataArray, "LawyerContracts": dataArray,
} }
console.log(lawyer);
$.ajax({ $.ajax({
url: "/lawyer/create", url: "/lawyers/create",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(lawyer) data: JSON.stringify(lawyer)

View File

@ -9,14 +9,14 @@ var currentLawyer = null;
window.addEventListener('load', async () => { window.addEventListener('load', async () => {
await $.ajax({ await $.ajax({
url: "/contract/getallbyuser", url: "/contracts/getallbyuser",
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}).done((result) => { }).done((result) => {
contracts = result; contracts = result;
}); });
await $.ajax({ await $.ajax({
url: `/lawyer/get?id=${currentLawyerId}`, url: `/lawyers/get?id=${currentLawyerId}`,
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}).done((result) => { }).done((result) => {
@ -25,7 +25,7 @@ window.addEventListener('load', async () => {
contracts.forEach((contract) => createRowForContractsTable(contract)); contracts.forEach((contract) => createRowForContractsTable(contract));
}) })
/*createBtn.addEventListener('click', () => { createBtn.addEventListener('click', () => {
var lawyerCasesUpdate = { var lawyerCasesUpdate = {
"Id": currentLawyer.id, "Id": currentLawyer.id,
"Service": serviceInput.value, "Service": serviceInput.value,
@ -42,7 +42,7 @@ window.addEventListener('load', async () => {
}).done(() => { }).done(() => {
window.location.href = "/Home/Lawyers"; window.location.href = "/Home/Lawyers";
}); });
})*/ })
const createRowForContractsTable = (contract) => { const createRowForContractsTable = (contract) => {
const { id, service, coast, date} = contract; const { id, service, coast, date} = contract;

View File

@ -10,7 +10,7 @@ removeButtons.forEach(function (button) {
var result = confirm("Вы уверены, что хотите удалить эту запись?"); var result = confirm("Вы уверены, что хотите удалить эту запись?");
if (result) { if (result) {
$.ajax({ $.ajax({
url: "/lawyer/delete", url: "/lawyers/delete",
type: "POST", type: "POST",
data: { Id: id } data: { Id: id }
}).done(() => { }).done(() => {

View File

@ -12,9 +12,12 @@ namespace CaseAccountingRestApi.Controllers
{ {
private readonly ILawyerLogic lawyerLogic; private readonly ILawyerLogic lawyerLogic;
public LawyerController(ILawyerLogic logic) private readonly ICaseLogic _caseLogic;
public LawyerController(ILawyerLogic logic, ICaseLogic caseLogic)
{ {
lawyerLogic = logic; lawyerLogic = logic;
_caseLogic = caseLogic;
} }
[HttpGet] [HttpGet]
@ -81,5 +84,31 @@ namespace CaseAccountingRestApi.Controllers
throw; throw;
} }
} }
[HttpGet]
public List<CaseViewModel>? GetAllGroups()
{
try
{
return _caseLogic.ReadList(null);
}
catch (Exception ex)
{
throw;
}
}
[HttpGet]
public List<LawyerViewModel>? GetAllByUserAndSpecialization(int userId, int specialization)
{
try
{
return lawyerLogic.ReadList(new LawyerSearchModel { UserId = userId, SpecializationId = specialization });
}
catch (Exception ex)
{
throw;
}
}
} }
} }