PIbd-23_Nevaeva_K.A._Travel.../TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ReportLogic.cs

130 lines
4.9 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TravelCompanyBusinessLogic.BusinessLogic.OfficePackage.HelperModels;
using TravelCompanyBusinessLogic.OfficePackage;
using TravelCompanyBusinessLogic.OfficePackage.HelperModels;
using TravelCompanyContracts.BindingModels;
using TravelCompanyContracts.BusinessLogicsContracts;
using TravelCompanyContracts.SearchModels;
using TravelCompanyContracts.StoragesContracts;
using TravelCompanyContracts.ViewModels;
namespace TravelCompanyBusinessLogic.BusinessLogic
{
public class ReportLogic : IReportLogic
{
private readonly IConditionStorage _conditionStorage;
private readonly ITravelStorage _travelStorage;
private readonly IOrderStorage _orderStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ITravelStorage travelStorage, IConditionStorage
conditionStorage, IOrderStorage orderStorage,
AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord,
AbstractSaveToPdf saveToPdf)
{
_travelStorage = travelStorage;
_conditionStorage = conditionStorage;
_orderStorage = orderStorage;
_saveToExcel = saveToExcel;
_saveToWord = saveToWord;
_saveToPdf = saveToPdf;
}
/// <summary>
/// Получение списка компонент с указанием, в каких изделиях используются
/// </summary>
/// <returns></returns>
public List<ReportTravelConditionViewModel> GetTravelCondition()
{
var conditions = _conditionStorage.GetFullList();
var travels = _travelStorage.GetFullList();
var list = new List<ReportTravelConditionViewModel>();
foreach (var travel in travels)
{
var record = new ReportTravelConditionViewModel
{
TravelName = travel.TravelName,
Conditions = new List<Tuple<string, int>>(),
TotalCount = 0
};
foreach (var condition in conditions)
{
if (travel.TravelConditions.ContainsKey(condition.Id))
{
record.Conditions.Add(new(condition.ConditionName, travel.TravelConditions[condition.Id].Item2));
record.TotalCount +=
travel.TravelConditions[condition.Id].Item2;
}
}
list.Add(record);
}
return list;
}
/// <summary>
/// Получение списка заказов за определенный период
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel
{
DateFrom = model.DateFrom,
DateTo = model.DateTo
})
.Select(x => new ReportOrdersViewModel
{
Id = x.Id,
DateCreate = x.DateCreate,
TravelName = x.TravelName,
Sum = x.Sum,
Status = x.Status.ToString(),
})
.ToList();
}
/// <summary>
/// Сохранение компонент в файл-Word
/// </summary>
/// <param name="model"></param>
public void SaveTravelsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список путешествий",
Travels = _travelStorage.GetFullList()
});
}
/// <summary>
/// Сохранение компонент с указаеним продуктов в файл-Excel
/// </summary>
/// <param name="model"></param>
public void SaveTravelConditionToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список путешествий",
TravelConditions = GetTravelCondition()
});
}
public void SaveOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateDoc(new PdfInfo
{
FileName = model.FileName,
Title = "Список заказов",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Orders = GetOrders(model)
});
}
}
}