103 lines
4.2 KiB
C#
103 lines
4.2 KiB
C#
using CaseAccountingBusinessLogic.OfficePackage;
|
||
using CaseAccountingBusinessLogic.OfficePackage.HelperModels;
|
||
using CaseAccountingContracts.BindingModels;
|
||
using CaseAccountingContracts.BusinessLogicContracts;
|
||
using CaseAccountingContracts.SearchModels;
|
||
using CaseAccountingContracts.StoragesContracts;
|
||
using CaseAccountingContracts.ViewModels;
|
||
using CaseAccountingDataBaseImplement.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace CaseAccountingBusinessLogic.BusinessLogics
|
||
{
|
||
public class ReportCustomerLogic : IReportCustomerLogic
|
||
{
|
||
private readonly ICaseStorage _caseStorage;
|
||
private readonly IHearingStorage _hearingStorage;
|
||
private readonly ILawyerStorage _lawyerStorage;
|
||
private readonly ISpecializationStorage _specializationStorage;
|
||
private readonly WordBuilderCustomer _wordBuilder;
|
||
private readonly ExcelBuilderCustomer _excelBuilder;
|
||
|
||
public ReportCustomerLogic(ICaseStorage caseStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, ISpecializationStorage specializationStorage,
|
||
WordBuilderCustomer wordBuilder, ExcelBuilderCustomer excelBuilder)
|
||
{
|
||
_caseStorage = caseStorage;
|
||
_hearingStorage = hearingStorage;
|
||
_lawyerStorage = lawyerStorage;
|
||
_specializationStorage = specializationStorage;
|
||
_wordBuilder = wordBuilder;
|
||
_excelBuilder = excelBuilder;
|
||
}
|
||
|
||
public List<ReportHearingSpecializationViewModel> GetHearingSpecialization(ReportBindingModel model)
|
||
{
|
||
var result = _hearingStorage
|
||
.GetFilteredList(new HearingSearchModel { UserId = model.UserId })
|
||
.Where(x => model.DateFrom <= x.Date && model.DateTo >= x.Date)
|
||
.Select(hearing => new ReportHearingSpecializationViewModel
|
||
{
|
||
Information = hearing.Information,
|
||
Date = hearing.Date,
|
||
Specialization = _caseStorage.GetElement(new CaseSearchModel
|
||
{
|
||
Id = hearing.CaseId
|
||
})?
|
||
.Specialization ?? "Не удалось найти специализацию."
|
||
})
|
||
.ToList();
|
||
return result;
|
||
}
|
||
|
||
public List<ReportLawyerHearingViewModel> GetLawyersHearing(List<LawyerViewModel> lawyers)
|
||
{
|
||
List <ReportLawyerHearingViewModel> list = new();
|
||
foreach (var lawyer in lawyers)
|
||
{
|
||
ReportLawyerHearingViewModel report = new ReportLawyerHearingViewModel
|
||
{
|
||
Lawyer = lawyer.Surname + " " + lawyer.Name + " " + lawyer.Patronymic,
|
||
Hearings = new()
|
||
};
|
||
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 list;
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|