Case_accounting/CaseAccounting/CaseAccountingBusinessLogics/BusinessLogics/ReportCustomerLogic.cs

113 lines
4.4 KiB
C#
Raw Normal View History

2023-05-20 01:21:33 +04:00
using CaseAccountingBusinessLogic.OfficePackage;
using CaseAccountingBusinessLogic.OfficePackage.HelperModels;
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.BusinessLogicContracts;
using CaseAccountingContracts.SearchModels;
using CaseAccountingContracts.StoragesContracts;
using CaseAccountingContracts.ViewModels;
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;
2023-05-20 01:21:33 +04:00
private readonly WordBuilderCustomer _wordBuilder;
private readonly ExcelBuilderCustomer _excelBuilder;
2023-05-20 01:21:33 +04:00
public ReportCustomerLogic(ICaseStorage caseStorage, IHearingStorage hearingStorage, ILawyerStorage lawyerStorage, ISpecializationStorage specializationStorage,
WordBuilderCustomer wordBuilder, ExcelBuilderCustomer excelBuilder)
{
_caseStorage = caseStorage;
_hearingStorage = hearingStorage;
_lawyerStorage = lawyerStorage;
_specializationStorage = specializationStorage;
2023-05-20 01:21:33 +04:00
_wordBuilder = wordBuilder;
_excelBuilder = excelBuilder;
}
public List<ReportHearingSpecializationViewModel> GetHearingSpecialization(ReportBindingModel model)
{
var result = _hearingStorage
.GetFilteredList(new HearingSearchModel { UserId = model.UserId })
2023-04-09 01:01:14 +04:00
.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;
}
2023-05-20 01:21:33 +04:00
public List<ReportLawyerHearingViewModel> GetLawyersHearing(List<LawyerViewModel> lawyers)
{
var reportRecords = new List<ReportLawyerHearingViewModel>();
foreach (var lawyer in lawyers)
{
2023-05-20 01:21:33 +04:00
var hearings = _lawyerStorage.GetLawyerCases(new() { Id = lawyer.Id })
.SelectMany(_case => _caseStorage.GetCaseHearings(new() { Id = _case.Id }))
.Select(hearing => hearing.Information)
.ToList();
ReportLawyerHearingViewModel reportRecord = new()
{
2023-05-20 01:21:33 +04:00
Lawyer = lawyer.Name + " " + lawyer.Surname + ", " + lawyer.Patronymic,
Hearings = hearings
};
2023-05-20 01:21:33 +04:00
reportRecords.Add(reportRecord);
}
2023-05-20 01:21:33 +04:00
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();
}
2023-05-20 01:21:33 +04:00
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;
}
}
}