diff --git a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs index f5e211f..12003e2 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs +++ b/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs @@ -5,6 +5,7 @@ using CaseAccountingContracts.BusinessLogicContracts; using CaseAccountingContracts.SearchModels; using CaseAccountingContracts.StoragesContracts; using CaseAccountingContracts.ViewModels; +using CaseAccountingDataBaseImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -54,36 +55,25 @@ namespace CaseAccountingBusinessLogic.BusinessLogics public List GetLawyersHearing(List lawyers) { - var reportRecords = new List(); + List list = new(); foreach (var lawyer in lawyers) { - var hearings = _lawyerStorage.GetLawyerCases(new() { Id = lawyer.Id }) - .SelectMany(_case => _caseStorage.GetCaseHearings(new() { Id = _case.Id })) - .Select(hearing => hearing.Information) - .ToList(); - ReportLawyerHearingViewModel reportRecord = new() + ReportLawyerHearingViewModel report = new ReportLawyerHearingViewModel { - Lawyer = lawyer.Name + " " + lawyer.Surname + ", " + lawyer.Patronymic, - Hearings = hearings + Lawyer = lawyer.Surname + " " + lawyer.Name + " " + lawyer.Patronymic, + Hearings = new() }; - reportRecords.Add(reportRecord); + var cases = _caseStorage.GetCaseMTM(lawyer.Id); + foreach (var caseModel in cases) + { + foreach (var hearing in _hearingStorage.GetFilteredList(new HearingSearchModel { CaseId = caseModel.Id })) + { + report.Hearings.Add("Номер слушания: " + hearing.Id.ToString()); + } + } + list.Add(report); } - return reportRecords; - } - - public void SaveHearingSpecializationToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - - public void SaveLawyerHearingToExcelFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - - public void SaveLawyerHearingToWordFile(ReportBindingModel model) - { - throw new NotImplementedException(); + return list; } public byte[] SaveListFile(LawyerHearingListBindingModel model) diff --git a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs index 5dc559d..8fe434e 100644 --- a/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs +++ b/CaseAccounting/CaseAccountingContracts/BusinessLogicContracts/IReportCustomerLogic.cs @@ -15,11 +15,5 @@ namespace CaseAccountingContracts.BusinessLogicContracts List GetHearingSpecialization(ReportBindingModel model); byte[] SaveListFile(LawyerHearingListBindingModel model); - - void SaveLawyerHearingToWordFile(ReportBindingModel model); - - void SaveLawyerHearingToExcelFile(ReportBindingModel model); - - void SaveHearingSpecializationToPdfFile(ReportBindingModel model); } } diff --git a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs index a119f8c..280f367 100644 --- a/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs +++ b/CaseAccounting/CaseAccountingContracts/StoragesContracts/ICaseStorage.cs @@ -18,7 +18,7 @@ namespace CaseAccountingContracts.StoragesContracts CaseViewModel? Update(CaseBindingModel model); CaseViewModel? Delete(CaseBindingModel model); - List GetCaseHearings(CaseSearchModel model); + List GetCaseMTM(int lawyerId); List? GetSpecializationCases(); } } diff --git a/CaseAccounting/CaseAccountingCustomerView/CaseAccountingCustomerView.csproj b/CaseAccounting/CaseAccountingCustomerView/CaseAccountingCustomerView.csproj index 083008b..0b83c0b 100644 --- a/CaseAccounting/CaseAccountingCustomerView/CaseAccountingCustomerView.csproj +++ b/CaseAccounting/CaseAccountingCustomerView/CaseAccountingCustomerView.csproj @@ -6,6 +6,10 @@ enable + + + + diff --git a/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs index ebe62bd..c26dbf7 100644 --- a/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingCustomerView/Controllers/HomeController.cs @@ -102,14 +102,14 @@ namespace CaseAccountingCustomerView.Controllers } [HttpPost] - public int[]? SpecializationCaselist([FromBody] LawyerHearingListBindingModel listModel) + public int[]? HearingLawyerlist([FromBody] LawyerHearingListBindingModel listModel) { if (APIUser.User == null) { return Array.Empty(); } byte[]? file = APIUser.PostRequestWithResult - ("api/reportprovider/specializationcaselist", listModel); + ("api/reportcustomer/lawyerhearinglist", listModel); return file!.Select(b => (int)b).ToArray(); } diff --git a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js index b775f3a..1ea3643 100644 --- a/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js +++ b/CaseAccounting/CaseAccountingCustomerView/wwwroot/js/Report/reportlist.js @@ -7,15 +7,31 @@ 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)); - }); +window.addEventListener('load', async () => { + try { + await $.ajax({ + url: `/lawyers/getallbyuser`, + type: "GET", + contentType: "json" + }).done((result) => { + lawyers = result; + lawyers.forEach((lawyerModel) => { + const { id, name, surname, patronymic, experience, specialization } = lawyerModel; + 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)); + }); + }); + } catch (error) { + console.error(error); + } }) createBtn.addEventListener('click', () => { @@ -23,7 +39,6 @@ createBtn.addEventListener('click', () => { "Lawyers": Array.from(dataArray), "FileType": fileType.value }; - console.log(listModel); $.ajax({ url: "/home/hearinglawyerlist", type: "POST", @@ -61,38 +76,16 @@ const saveFile = async function (bytes, fileType) { } } -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"); + row.classList.add("bg-info"); } else { dataArray.splice(index, 1); - row.classList.remove("bg-success"); + row.classList.remove("bg-info"); } console.log(dataArray); -} \ No newline at end of file +} diff --git a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs index c665ae2..37811e4 100644 --- a/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs +++ b/CaseAccounting/CaseAccountingDataBaseImplement/Implements/CaseStorage.cs @@ -171,18 +171,18 @@ namespace CaseAccountingDataBaseImplement.Implements } } - public List GetCaseHearings(CaseSearchModel model) + public List GetCaseMTM(int lawyerId) { - if (model == null) - { - return new(); - } using var context = new CaseAccountingDatabase(); - var hearings = context.Hearings - .Where(x => x.CaseId == model.Id) + var lawyersId = context.CaseLawyers + .Where(x => x.LawyerId == lawyerId) + .Select(x => x.CaseId).ToList(); + return context.Cases + .Include(x => x.Specialization) + .Include(x => x.User) + .Where(X => lawyersId.Contains(X.Id)) .Select(x => x.GetViewModel) .ToList(); - return hearings; } public List? GetSpecializationCases() diff --git a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs index 7aae007..f94615e 100644 --- a/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs +++ b/CaseAccounting/CaseAccountingProviderView/Controllers/HomeController.cs @@ -53,7 +53,7 @@ namespace CaseAccountingProviderView.Controllers return Array.Empty(); } byte[]? file = APIUser.PostRequestWithResult - ("api/reportcustomer/lawyerhearinglist", listModel); + ("api/reportprovider/specializationcaselist", listModel); return file!.Select(b => (int)b).ToArray(); }