Compare commits

...

4 Commits

27 changed files with 1121 additions and 87 deletions

View File

@ -1,4 +1,6 @@
using CaseAccountingContracts.BindingModels; using CaseAccountingBusinessLogic.OfficePackage;
using CaseAccountingBusinessLogic.OfficePackage.HelperModels;
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.BusinessLogicContracts;
using CaseAccountingContracts.SearchModels; using CaseAccountingContracts.SearchModels;
using CaseAccountingContracts.StoragesContracts; using CaseAccountingContracts.StoragesContracts;
@ -17,13 +19,18 @@ namespace CaseAccountingBusinessLogic.BusinessLogics
private readonly IHearingStorage _hearingStorage; private readonly IHearingStorage _hearingStorage;
private readonly ILawyerStorage _lawyerStorage; private readonly ILawyerStorage _lawyerStorage;
private readonly ISpecializationStorage _specializationStorage; private readonly ISpecializationStorage _specializationStorage;
private readonly WordBuilderCustomer _wordBuilder;
private readonly ExcelBuilderCustomer _excelBuilder;
public ReportCustomerLogic(ICaseStorage caseStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, ISpecializationStorage specializationStorage) public ReportCustomerLogic(ICaseStorage caseStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, ISpecializationStorage specializationStorage,
WordBuilderCustomer wordBuilder, ExcelBuilderCustomer excelBuilder)
{ {
_caseStorage = caseStorage; _caseStorage = caseStorage;
_hearingStorage = hearingStorage; _hearingStorage = hearingStorage;
_lawyerStorage = lawyerStorage; _lawyerStorage = lawyerStorage;
_specializationStorage = specializationStorage; _specializationStorage = specializationStorage;
_wordBuilder = wordBuilder;
_excelBuilder = excelBuilder;
} }
public List<ReportHearingSpecializationViewModel> GetHearingSpecialization(ReportBindingModel model) public List<ReportHearingSpecializationViewModel> GetHearingSpecialization(ReportBindingModel model)
@ -45,34 +52,23 @@ namespace CaseAccountingBusinessLogic.BusinessLogics
return result; return result;
} }
public List<ReportLawyerHearingViewModel> GetLawyerHearing(List<LawyerViewModel> models) public List<ReportLawyerHearingViewModel> GetLawyersHearing(List<LawyerViewModel> lawyers)
{ {
var lawyers = new List<LawyerViewModel>(); var reportRecords = new List<ReportLawyerHearingViewModel>();
foreach (var model in models)
{
lawyers.Add(_lawyerStorage.GetElement(new LawyerSearchModel { Id = model.Id}));
}
var list = new List<ReportLawyerHearingViewModel>();
foreach (var lawyer in lawyers) foreach (var lawyer in lawyers)
{ {
var record = new ReportLawyerHearingViewModel var hearings = _lawyerStorage.GetLawyerCases(new() { Id = lawyer.Id })
.SelectMany(_case => _caseStorage.GetCaseHearings(new() { Id = _case.Id }))
.Select(hearing => hearing.Information)
.ToList();
ReportLawyerHearingViewModel reportRecord = new()
{ {
Name = lawyer.Name, Lawyer = lawyer.Name + " " + lawyer.Surname + ", " + lawyer.Patronymic,
Surname = lawyer.Surname, Hearings = hearings
Patronymic = lawyer.Patronymic,
Hearings = new List<(DateTime Date, string Information)>()
}; };
var cases = _caseStorage.GetFullList() reportRecords.Add(reportRecord);
.Where(x => x.Lawyers.ContainsKey(lawyer.Id));
foreach (var _case in cases)
{
record.Hearings.Add((_hearingStorage.GetElement(new HearingSearchModel { CaseId = _case.Id}).Date,
_hearingStorage.GetElement(new HearingSearchModel { CaseId = _case.Id })?.Information ?? "Не удалось найти информацию."));
} }
list.Add(record); return reportRecords;
}
return list;
} }
public void SaveHearingSpecializationToPdfFile(ReportBindingModel model) public void SaveHearingSpecializationToPdfFile(ReportBindingModel model)
@ -89,5 +85,28 @@ namespace CaseAccountingBusinessLogic.BusinessLogics
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte[] SaveListFile(LawyerHearingListBindingModel model)
{
byte[] file = Array.Empty<byte>();
string title = "Список слушаний по выбранным юристам";
if (model.FileType == "docx")
{
_wordBuilder.CreateDocument();
_wordBuilder.CreateTitle(title);
_wordBuilder.CreateLawyersHearingTable(GetLawyersHearing(model.Lawyers));
file = _wordBuilder.GetFile();
}
else if (model.FileType == "xlsx")
{
_excelBuilder.CreateDocument();
_excelBuilder.CreateTitle(title);
_excelBuilder.CreateLawyersHearingTable(GetLawyersHearing(model.Lawyers));
file = _excelBuilder.GetFile();
}
return file;
}
} }
} }

View File

@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\CaseAccountingContracts\CaseAccountingContracts.csproj" /> <ProjectReference Include="..\CaseAccountingContracts\CaseAccountingContracts.csproj" />
<ProjectReference Include="..\CaseAccountingDataBaseImplement\CaseAccountingDataBaseImplement.csproj" />
<ProjectReference Include="..\CaseAccountingDataModels\CaseAccountingDataModels.csproj" /> <ProjectReference Include="..\CaseAccountingDataModels\CaseAccountingDataModels.csproj" />
</ItemGroup> </ItemGroup>

View File

@ -290,7 +290,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage
}); });
} }
/*public void CreateLawyersHearingsTable(List<ReportLawyerHearingViewModel> data) public void CreateLawyersHearingTable(List<ReportLawyerHearingViewModel> data)
{ {
if (worksheet == null || shareStringPart == null) if (worksheet == null || shareStringPart == null)
{ {
@ -337,7 +337,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage
StyleIndex = 1 StyleIndex = 1
}); });
currentRow++; currentRow++;
foreach (string discipline in student.Disciplines) foreach (string hearing in lawyer.Hearings)
{ {
InsertCellInWorksheet(new ExcelCellData InsertCellInWorksheet(new ExcelCellData
{ {
@ -350,7 +350,7 @@ namespace CaseAccountingBusinessLogic.OfficePackage
{ {
ColumnName = "B", ColumnName = "B",
RowIndex = currentRow, RowIndex = currentRow,
Text = discipline, Text = hearing,
StyleIndex = 1 StyleIndex = 1
}); });
currentRow++; currentRow++;

View File

@ -0,0 +1,174 @@
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CaseAccountingContracts.ViewModels;
namespace CaseAccountingBusinessLogic.OfficePackage.HelperModels
{
public class WordBuilderCustomer
{
private readonly string tempFileName = "temp.docx";
private WordprocessingDocument? wordDocument;
private Body? documentBody;
public void CreateDocument()
{
wordDocument = WordprocessingDocument.Create(tempFileName,
WordprocessingDocumentType.Document);
MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
documentBody = mainPart.Document.AppendChild(new Body());
}
public void CreateParagraph(string text)
{
if (documentBody == null)
{
return;
}
Paragraph paragraph = new();
Run run = new();
run.AppendChild(new Text
{
Text = text
});
paragraph.AppendChild(run);
documentBody.AppendChild(paragraph);
}
public void CreateTitle(string text)
{
if (documentBody == null)
{
return;
}
Paragraph paragraph = new();
Run run = new();
RunProperties properties = new();
properties.AppendChild(new Bold());
run.AppendChild(properties);
run.AppendChild(new Text
{
Text = text
});
paragraph.AppendChild(run);
documentBody.AppendChild(paragraph);
}
private TableCell CreateTableCell(string text, bool inHead = false, int? cellWidth = null)
{
Run run = new();
TableCell tableCell = new();
TableCellProperties cellProperties = new()
{
TableCellWidth = new()
{
Width = cellWidth.ToString()
},
TableCellMargin = new()
{
LeftMargin = new()
{
Width = "100"
}
}
};
if (inHead)
{
Shading shading = new()
{
Color = "auto",
Fill = "e0e8ff",
Val = ShadingPatternValues.Clear
};
cellProperties.Append(shading);
RunProperties properties = new();
properties.AppendChild(new Bold());
run.AppendChild(properties);
}
run.AppendChild(new Text
{
Text = text
});
Paragraph paragraph = new(run);
tableCell.AppendChild(paragraph);
tableCell.Append(cellProperties);
return tableCell;
}
protected void CreateTable(WordTableData tableData)
{
if (documentBody == null || tableData == null)
{
return;
}
var table = new Table();
TableProperties tableProperties = new(
new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 3 }
)
);
table.AppendChild(tableProperties);
table.Append(new TableRow(tableData.Columns.Select(x => CreateTableCell(x.Item1, true, x.Item2))));
table.Append(tableData.Rows.Select(x => new TableRow(x.Select(y => CreateTableCell(y)))));
documentBody.AppendChild(table);
}
private void Save()
{
if (documentBody == null || wordDocument == null)
{
return;
}
wordDocument.MainDocumentPart!.Document.Save();
wordDocument.Dispose();
}
public byte[] GetFile()
{
Save();
byte[] file = File.ReadAllBytes(tempFileName);
File.Delete(tempFileName);
return file;
}
public void CreateLawyersHearingTable(List<ReportLawyerHearingViewModel> data)
{
List<List<string>> rows = new();
foreach (ReportLawyerHearingViewModel lawyer in data)
{
List<string> lawyerCells = new() { lawyer.Lawyer, "" };
rows.Add(lawyerCells);
List<string> hearingCells;
foreach (string hearing in lawyer.Hearings)
{
hearingCells = new() { "", hearing };
rows.Add(hearingCells);
}
}
WordTableData wordTable = new()
{
Columns = new List<(string, int)>()
{
("Юрист", 3000),
("Слушание", 3000)
},
Rows = rows
};
CreateTable(wordTable);
}
}
}

View File

@ -0,0 +1,15 @@
using CaseAccountingContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingContracts.BindingModels
{
public class LawyerHearingListBindingModel
{
public string FileType { get; set; } = string.Empty;
public List<LawyerViewModel> Lawyers { get; set; } = new();
}
}

View File

@ -10,10 +10,12 @@ namespace CaseAccountingContracts.BusinessLogicContracts
{ {
public interface IReportCustomerLogic public interface IReportCustomerLogic
{ {
List<ReportLawyerHearingViewModel> GetLawyerHearing(List<LawyerViewModel> models); List<ReportLawyerHearingViewModel> GetLawyersHearing(List<LawyerViewModel> models);
List<ReportHearingSpecializationViewModel> GetHearingSpecialization(ReportBindingModel model); List<ReportHearingSpecializationViewModel> GetHearingSpecialization(ReportBindingModel model);
byte[] SaveListFile(LawyerHearingListBindingModel model);
void SaveLawyerHearingToWordFile(ReportBindingModel model); void SaveLawyerHearingToWordFile(ReportBindingModel model);
void SaveLawyerHearingToExcelFile(ReportBindingModel model); void SaveLawyerHearingToExcelFile(ReportBindingModel model);

View File

@ -17,5 +17,7 @@ namespace CaseAccountingContracts.StoragesContracts
CaseViewModel? Insert(CaseBindingModel model); CaseViewModel? Insert(CaseBindingModel model);
CaseViewModel? Update(CaseBindingModel model); CaseViewModel? Update(CaseBindingModel model);
CaseViewModel? Delete(CaseBindingModel model); CaseViewModel? Delete(CaseBindingModel model);
List<HearingViewModel> GetCaseHearings(CaseSearchModel model);
} }
} }

View File

@ -17,6 +17,8 @@ namespace CaseAccountingContracts.StoragesContracts
LawyerViewModel? Insert(LawyerBindingModel model); LawyerViewModel? Insert(LawyerBindingModel model);
LawyerViewModel? Update(LawyerBindingModel model); LawyerViewModel? Update(LawyerBindingModel model);
LawyerViewModel? Delete(LawyerBindingModel model); LawyerViewModel? Delete(LawyerBindingModel model);
List<CaseViewModel> GetLawyerCases(LawyerSearchModel model);
List<LawyerViewModel> GetLawyerMTM(int caseId); List<LawyerViewModel> GetLawyerMTM(int caseId);
} }
} }

View File

@ -8,12 +8,7 @@ namespace CaseAccountingContracts.ViewModels
{ {
public class ReportLawyerHearingViewModel public class ReportLawyerHearingViewModel
{ {
public string Name { get; set; } = string.Empty; public string Lawyer { get; set; } = string.Empty;
public List<string> Hearings { get; set; } = new();
public string Surname { get; set; } = string.Empty;
public string Patronymic { get; set; } = string.Empty;
public List<(DateTime Date, string Information)> Hearings { get; set; } = new();
} }
} }

View File

@ -39,5 +39,25 @@ namespace CaseAccountingCustomerView
throw new Exception(result); throw new Exception(result);
} }
} }
public static O? PostRequestWithResult<I, O>(string requestUrl, I model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = _client.PostAsync(requestUrl, data);
var result = response.Result.Content.ReadAsStringAsync().Result;
if (response.Result.IsSuccessStatusCode)
{
var temp = JsonConvert.DeserializeObject<O>(result);
return temp;
}
else
{
return default;
}
}
} }
} }

View File

@ -100,5 +100,22 @@ namespace CaseAccountingCustomerView.Controllers
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
[HttpPost]
public int[]? HearingLawyerList([FromBody] LawyerHearingListBindingModel listModel)
{
if (APIUser.User == null)
{
return Array.Empty<int>();
}
byte[]? file = APIUser.PostRequestWithResult<LawyerHearingListBindingModel, byte[]>
("api/reportcustomer/lawyerhearinglist", listModel);
return file!.Select(b => (int)b).ToArray();
}
public IActionResult HearingLawyerList()
{
return View();
}
} }
} }

View File

@ -6,7 +6,7 @@
@{ @{
<h4 class="fw-bold" id="vb-id" data-id="@ViewBag.Contract.Id">Изменение данных контракта</h4> <h4 class="fw-bold" id="contr-id" data-id="@ViewBag.Contract.Id">Изменение данных контракта</h4>
if (ViewBag.Contract == null) if (ViewBag.Contract == null)
{ {

View File

@ -0,0 +1,44 @@
@{
ViewData["Title"] = "Список слушаний по юристам";
}
<h4 class="fw-bold">Список слушаний по юристам</h4>
<div id="error-div-shell" class="error-div-shell mb-2">
<div>
<p id="error-p" class="error-p"></p>
</div>
</div>
<select id="file-type">
<option>docx</option>
<option>xlsx</option>
</select>
<button id="create-button" type="button" class="button-primary text-button">
Показать итоговый вариант
</button>
<button id="save-button" type="button" class="button-primary text-button">
Сохранить результат
</button>
<div>
<div class="scrollable-table">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Имя</th>
<th>Фамилия</th>
<th>Отчество</th>
<th>Опыт работы</th>
<th>Специализация</th>
</tr>
</thead>
<tbody id="scrollable-table__tbody">
</tbody>
</table>
</div>
</div>
<script src="~/js/Report/reportlist.js" asp-append-version="true"></script>

View File

@ -48,7 +48,7 @@
<a id="add-lawyer-button-@item.Id" class="btn btn-secondary" asp-controller="Specializations" asp-action="AddLawyer" asp-route-id="@item.Id">Назначить специализацию для юриста</a> <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> <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="Specializations" asp-action="Update" asp-route-id="@item.Id">Изменить</a>
</td> </td>
<td> <td>
<a id="remove-button-@item.Id" class="btn btn-secondary remove-btn" data-id="@item.Id">Удалить</a> <a id="remove-button-@item.Id" class="btn btn-secondary remove-btn" data-id="@item.Id">Удалить</a>

View File

@ -6,7 +6,7 @@
@{ @{
<h4 class="fw-bold" id="vb-id" data-id="@ViewBag.Lawyer.Id">Изменение данных юриста</h4> <h4 class="fw-bold" id="lawyer-id" data-id="@ViewBag.Lawyer.Id">Изменение данных юриста</h4>
if (ViewBag.Lawyer == null) if (ViewBag.Lawyer == null)
{ {
@ -28,9 +28,25 @@
<p class="mb-0">Опыт работы:</p> <p class="mb-0">Опыт работы:</p>
<input value="@ViewBag.Lawyer.Experience" type="number" id="experience-input" name="experience" class="form-control mb-3" /> <input value="@ViewBag.Lawyer.Experience" type="number" id="experience-input" name="experience" class="form-control mb-3" />
<button id="update-button" type="button" class="button-primary text-button"> <button id="create-button" type="button" class="btn btn-primary text-button">
Сохранить изменения Сохранить изменения
</button> </button>
<div class="mt-4">
<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>
} }
<script src="~/js/Lawyers/lawyer-update.js" asp-append-version="true"></script> <script src="~/js/Lawyers/lawyer-update.js" asp-append-version="true"></script>

View File

@ -3,7 +3,7 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - CaseAccountingCustomerView</title> <title>@ViewData["Title"] - Юридическая фирма «Вас обманут» "Заказчик"</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /> <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/CaseAccountingCustomerView.styles.css" asp-append-version="true" /> <link rel="stylesheet" href="~/CaseAccountingCustomerView.styles.css" asp-append-version="true" />
@ -12,7 +12,7 @@
<header> <header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">CaseAccountingCustomerView</a> <a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Юридическая фирма «Вас обманут» "Заказчик"</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation"> aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
@ -47,7 +47,7 @@
<footer class="border-top footer text-muted"> <footer class="border-top footer text-muted">
<div class="container"> <div class="container">
&copy; 2023 - CaseAccountingCustomerView - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> &copy; Юридическая фирма «Вас обманут» "Заказчик" - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div> </div>
</footer> </footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/jquery/dist/jquery.min.js"></script>

View File

@ -6,9 +6,9 @@
@{ @{
<h4 class="fw-bold" id="vb-id" data-id="@ViewBag.Specialization.Id">Изменение данных специализации</h4> <h4 class="fw-bold" id="spec-id" data-id="@ViewBag.Specialization.Id">Изменение данных специализации</h4>
if (ViewBag.EducationStatus == null) if (ViewBag.Specialization == null)
{ {
<h3 class="display-4">Войдите в аккаунт</h3> <h3 class="display-4">Войдите в аккаунт</h3>
return; return;

View File

@ -4,26 +4,26 @@ const coastInput = document.getElementById("coast-input")
const dateInput = document.getElementById("date-input") const dateInput = document.getElementById("date-input")
const contractId = document.getElementById("contr-id").dataset.id const contractId = document.getElementById("contr-id").dataset.id
contracts = []
window.addEventListener("load", () => {
const contractsResponse = $.ajax({
url: `/contracts/getallbyuser`,
type: "GET",
contentType: "json"
});
contracts = contractsResponse;
})
const correctData = () => {
return true;
};
updateBtn.addEventListener("click", () => { updateBtn.addEventListener("click", () => {
if (!correctData()) { if (!correctData()) {
return; return;
} }
if (!validate()) {
return;
}
});
const correctData = function () {
return true;
};
const validate = function () {
return true;
};
updateBtn.addEventListener("click", () => {
let contract = { let contract = {
"Id": parseInt(contractId), "Id": parseInt(contractId),
"Service": serviceInput.value, "Service": serviceInput.value,
@ -32,7 +32,7 @@ updateBtn.addEventListener("click", () => {
}; };
console.log(contract) console.log(contract)
$.ajax({ $.ajax({
url: "/lawyer/update", url: "/contracts/update",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(contract) data: JSON.stringify(contract)

View File

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

View File

@ -2,7 +2,7 @@
const tbody = document.getElementById("scrollable-table__tbody"); const tbody = document.getElementById("scrollable-table__tbody");
const serviceInput = document.getElementById("service-input"); const serviceInput = document.getElementById("service-input");
const coastInput = document.getElementById("coast-input"); const coastInput = document.getElementById("coast-input");
const currentLawyerId = document.getElementById("lawyer-data").dataset.id; const currentLawyerId = document.getElementById("lawyer-id").dataset.id;
var contracts = []; var contracts = [];
var dataArray = []; var dataArray = [];
var currentLawyer = null; var currentLawyer = null;
@ -15,14 +15,34 @@ window.addEventListener('load', async () => {
}).done((result) => { }).done((result) => {
contracts = result; contracts = result;
}); });
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) => {
currentLawyer = result; currentLawyer = result;
}); });
contracts.forEach((contract) => createRowForContractsTable(contract)); console.log(currentLawyerId);
console.log(currentLawyer);
contracts.forEach((contract) => {
const { id, service, coast, date } = contract;
const row = tbody.insertRow();
row.setAttribute("data-id", id);
const cells = [service, coast, formatDate(date)];
cells.forEach((value) => {
const cell = row.insertCell();
cell.textContent = value;
});
console.log(currentLawyer);
if (currentLawyer.ContractViewModels.find(x => parseInt(x.id) === parseInt(contract.id))) {
row.classList.add("bg-success");
dataArray.push(contract);
}
row.addEventListener('click', () => addAndRemoveFromList(row));
});
}) })
createBtn.addEventListener('click', () => { createBtn.addEventListener('click', () => {
@ -35,7 +55,7 @@ createBtn.addEventListener('click', () => {
"LawyerCases": currentLawyer.lawyerCases, "LawyerCases": currentLawyer.lawyerCases,
} }
$.ajax({ $.ajax({
url: "/lawyer/update", url: "/lawyers/update",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(lawyerCasesUpdate) data: JSON.stringify(lawyerCasesUpdate)
@ -44,25 +64,6 @@ createBtn.addEventListener('click', () => {
}); });
}) })
const createRowForContractsTable = (contract) => {
const { id, service, coast, date} = contract;
const row = tbody.insertRow();
row.setAttribute("data-id", id);
const cells = [service, coast, formatDate(date)];
cells.forEach((value) => {
const cell = row.insertCell();
cell.textContent = value;
});
if (currentLawyer.lawyerContracts.find(x => parseInt(x.id) === parseInt(contract.id))) {
row.classList.add("bg-success");
dataArray.push(contract);
}
row.addEventListener('click', () => addAndRemoveFromList(row));
};
const formatDate = (dateString) => { const formatDate = (dateString) => {
const date = new Date(dateString); const date = new Date(dateString);
const year = date.getFullYear(); const year = date.getFullYear();

View File

@ -0,0 +1,98 @@
const createBtn = document.getElementById("create-button")
const tbody = document.getElementById("scrollable-table__tbody")
const nameInput = document.getElementById("name-input")
var fileType = document.getElementById("file-type")
var lawyers = []
var dataArray = [];
const wordMIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
const excelMIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
window.addEventListener('load', () => {
$.ajax({
url: "/lawyers/getallbyuser",
type: "GET",
contentType: "json"
}).done((result) => {
lawyers = result;
lawyers.forEach((lawyer) => createRowForLawyersTable(lawyer));
});
})
createBtn.addEventListener('click', () => {
let listModel = {
"Lawyers": Array.from(dataArray),
"FileType": fileType.value
};
console.log(listModel);
$.ajax({
url: "/home/hearinglawyerlist",
type: "POST",
contentType: "application/json",
data: JSON.stringify(listModel)
}).done((file) => {
let byteArray = new Uint8Array(file);
saveFile(byteArray, fileType);
});
})
const saveFile = async function (bytes, fileType) {
if (window.showSaveFilePicker) {
let type;
if (fileType.value == "docx") {
type = {
description: "Microsoft Word (OpenXML)",
accept: { [wordMIME]: [".docx"] }
};
} else if (fileType.value == "xlsx") {
type = {
description: "Microsoft Excel (OpenXML)",
accept: { [excelMIME]: [".xlsx"] }
};
}
const opts = {
suggestedName: `lawyer-hearing-list.${fileType.value}`,
types: [type],
};
const handle = await showSaveFilePicker(opts);
const writable = await handle.createWritable();
await writable.write(bytes);
writable.close();
}
}
const createRowForLawyersTable = (lawyer) => {
const { id, name, surname, patronymic, experience, specialization } = lawyer;
const row = tbody.insertRow();
row.setAttribute("data-id", id);
const cells = [name, surname, patronymic, experience, specialization];
cells.forEach((value) => {
const cell = row.insertCell();
cell.textContent = value;
});
row.addEventListener('click', () => addAndRemoveFromList(row));
};
const formatDate = (dateString) => {
const date = new Date(dateString);
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + date.getDate()).slice(-2);
return `${year}-${month}-${day}`;
};
const addAndRemoveFromList = (row) => {
var id = parseInt(row.dataset.id);
console.log(lawyers.find(x => x.id === id))
var index = dataArray.indexOf(lawyers.find(x => x.id === id));
if (index === -1) {
dataArray.push(lawyers.find(x => x.id === id));
row.classList.add("bg-success");
} else {
dataArray.splice(index, 1);
row.classList.remove("bg-success");
}
console.log(dataArray);
}

View File

@ -1,4 +1,5 @@
const updateBtn = document.getElementById("update-button"); const updateBtn =
.getElementById("update-button");
const nameInput = document.getElementById("name-input") const nameInput = document.getElementById("name-input")
const specializationId = document.getElementById("spec-id").dataset.id const specializationId = document.getElementById("spec-id").dataset.id

View File

@ -170,5 +170,20 @@ namespace CaseAccountingDataBaseImplement.Implements
throw; throw;
} }
} }
public List<HearingViewModel> GetCaseHearings(CaseSearchModel model)
{
if (model == null)
{
return new();
}
using var context = new CaseAccountingDatabase();
var hearings = context.Hearings
.Where(x => x.CaseId == model.Id)
.Select(x => x.GetViewModel)
.ToList();
return hearings;
}
} }
} }

View File

@ -152,5 +152,19 @@ namespace CaseAccountingDataBaseImplement.Implements
throw; throw;
} }
} }
public List<CaseViewModel> GetLawyerCases(LawyerSearchModel model)
{
if (model == null)
{
return new();
}
using var context = new CaseAccountingDatabase();
var cases = context.CaseLawyers
.Where(x => x.LawyerId == model.Id)
.Select(x => x.Case.GetViewModel)
.ToList();
return cases;
}
} }
} }

View File

@ -0,0 +1,551 @@
// <auto-generated />
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("20230519222316_migrTilt")]
partial class migrTilt
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Annotation")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Applicant")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Defendant")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("SpecializationId")
.HasColumnType("integer");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SpecializationId");
b.HasIndex("UserId");
b.ToTable("Cases");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseDeal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("integer");
b.Property<int>("DealId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("DealId");
b.ToTable("CaseDeals");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.CaseLawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("integer");
b.Property<int>("LawyerId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("LawyerId");
b.ToTable("CaseLawyers");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Contract", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<decimal>("Coast")
.HasColumnType("numeric");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Service")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Contracts");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Deal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Responsibilities")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Deals");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.DealContract", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ContractId")
.HasColumnType("integer");
b.Property<int>("DealId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ContractId");
b.HasIndex("DealId");
b.ToTable("DealContracts");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Hearing", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CaseId")
.HasColumnType("integer");
b.Property<DateTime>("Date")
.HasColumnType("timestamp with time zone");
b.Property<string>("Information")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CaseId");
b.HasIndex("UserId");
b.ToTable("Hearings");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Lawyer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("Experience")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Patronymic")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("SpecializationId")
.HasColumnType("integer");
b.Property<string>("Surname")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SpecializationId");
b.HasIndex("UserId");
b.ToTable("Lawyers");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.LawyerContract", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ContractId")
.HasColumnType("integer");
b.Property<int>("LawyerId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ContractId");
b.HasIndex("LawyerId");
b.ToTable("LawyerContracts");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.Specialization", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("UserId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("Specializations");
});
modelBuilder.Entity("CaseAccountingDataBaseImplement.Models.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Login")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.Property<int>("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
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace CaseAccountingDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class migrTilt : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -0,0 +1,25 @@
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.BusinessLogicContracts;
using Microsoft.AspNetCore.Mvc;
namespace CaseAccountingRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ReportCustomerController : Controller
{
private readonly IReportCustomerLogic _reportCustomerLogic;
public ReportCustomerController(IReportCustomerLogic reportLogic)
{
_reportCustomerLogic = reportLogic;
}
[HttpPost]
public byte[] LawyerHearingList(LawyerHearingListBindingModel listModel)
{
byte[] file = _reportCustomerLogic.SaveListFile(listModel);
return file;
}
}
}